mirror of
				https://github.com/3ybactuk/marketplace-go-service-project.git
				synced 2025-10-31 06:23:44 +03:00 
			
		
		
		
	[hw-5] concurrency, graceful shutdown, concurrent tests
This commit is contained in:
		| @@ -12,11 +12,13 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/jackc/pgx/v5/pgxpool" | ||||
| 	_ "github.com/jackc/pgx/v5/stdlib" | ||||
| 	"github.com/ozontech/allure-go/pkg/framework/provider" | ||||
| 	"github.com/ozontech/allure-go/pkg/framework/suite" | ||||
| 	"github.com/pressly/goose/v3" | ||||
| 	"github.com/testcontainers/testcontainers-go" | ||||
| 	"github.com/testcontainers/testcontainers-go/wait" | ||||
| 	"go.uber.org/goleak" | ||||
| 	"google.golang.org/grpc" | ||||
| 	"google.golang.org/grpc/credentials/insecure" | ||||
|  | ||||
| @@ -47,10 +49,9 @@ func startPostgres(ctx context.Context, migrationsDir string) (*pgxpool.Pool, fu | ||||
| 			"POSTGRESQL_USERNAME": "user", | ||||
| 			"POSTGRESQL_PASSWORD": "postgres", | ||||
| 			"POSTGRESQL_DATABASE": "loms_test", | ||||
| 			"POSTGRESQL_PORT":     "5437", | ||||
| 		}, | ||||
| 		ExposedPorts: []string{"5437/tcp"}, | ||||
| 		WaitingFor:   wait.ForListeningPort("5437/tcp").WithStartupTimeout(30 * time.Second), | ||||
| 		ExposedPorts: []string{"5432/tcp"}, | ||||
| 		WaitingFor:   wait.ForListeningPort("5432/tcp").WithStartupTimeout(30 * time.Second), | ||||
| 	} | ||||
| 	container, err := testcontainers.GenericContainer(ctx, | ||||
| 		testcontainers.GenericContainerRequest{ContainerRequest: req, Started: true}) | ||||
| @@ -58,7 +59,7 @@ func startPostgres(ctx context.Context, migrationsDir string) (*pgxpool.Pool, fu | ||||
| 		return nil, nil, err | ||||
| 	} | ||||
|  | ||||
| 	endpoint, err := container.Endpoint(ctx, "") | ||||
| 	endpoint, err := container.PortEndpoint(ctx, "5432", "") | ||||
| 	if err != nil { | ||||
| 		container.Terminate(ctx) | ||||
| 		return nil, nil, err | ||||
| @@ -84,6 +85,7 @@ func startPostgres(ctx context.Context, migrationsDir string) (*pgxpool.Pool, fu | ||||
| 		container.Terminate(ctx) | ||||
| 		return nil, nil, err | ||||
| 	} | ||||
|  | ||||
| 	if err := goose.Up(std, migrationsDir); err != nil { | ||||
| 		container.Terminate(ctx) | ||||
| 		return nil, nil, err | ||||
| @@ -109,6 +111,8 @@ type LomsIntegrationSuite struct { | ||||
| } | ||||
|  | ||||
| func TestLomsIntegrationSuite(t *testing.T) { | ||||
| 	defer goleak.VerifyNone(t) | ||||
|  | ||||
| 	suite.RunSuite(t, new(LomsIntegrationSuite)) | ||||
| } | ||||
|  | ||||
| @@ -116,6 +120,8 @@ func (s *LomsIntegrationSuite) BeforeAll(t provider.T) { | ||||
| 	ctx := context.Background() | ||||
| 	t.WithNewStep("init cart-service", func(sCtx provider.StepCtx) { | ||||
| 		pool, cleanup, err := startPostgres(ctx, migrationsDir) | ||||
| 		sCtx.Require().NoError(err, "failed postgres setup") | ||||
|  | ||||
| 		s.cleanup = cleanup | ||||
|  | ||||
| 		orderRepo := ordersRepository.NewOrderRepository(pool) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Никита Шубин
					Никита Шубин