From a4e5cd69a1f3abdaf1b95fe617bff3a5d0290e7c Mon Sep 17 00:00:00 2001 From: Lars Gohr Date: Mon, 25 Dec 2023 22:07:55 +0100 Subject: [PATCH] :recycle: Make internal tests parallel --- localstack_internal_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/localstack_internal_test.go b/localstack_internal_test.go index 3b688558..e2fd83ed 100644 --- a/localstack_internal_test.go +++ b/localstack_internal_test.go @@ -31,7 +31,8 @@ import ( ) func TestInstance_Start_Fails(t *testing.T) { - for _, tt := range [...]struct { + t.Parallel() + for _, scenario := range [...]struct { when string given func(f *internalfakes.FakeDockerClient) *Instance then func(t *testing.T, err error, f *internalfakes.FakeDockerClient) @@ -108,7 +109,7 @@ func TestInstance_Start_Fails(t *testing.T) { AttachStdout: true, AttachStderr: true, }, config) - pm := nat.PortMap{} + pm := make(nat.PortMap, len(AvailableServices)) for service := range AvailableServices { pm[nat.Port(service.Port)] = []nat.PortBinding{{HostIP: "0.0.0.0", HostPort: ""}} } @@ -165,15 +166,18 @@ func TestInstance_Start_Fails(t *testing.T) { }, }, } { - t.Run(tt.when, func(t *testing.T) { + s := scenario + t.Run(s.when, func(t *testing.T) { + t.Parallel() f := &internalfakes.FakeDockerClient{} f.ContainerLogsReturns(io.NopCloser(strings.NewReader("")), nil) - tt.then(t, tt.given(f).Start(), f) + s.then(t, s.given(f).Start(), f) }) } } func TestInstance_StartWithContext_Fails_Stop_AfterTest(t *testing.T) { + t.Parallel() f := &internalfakes.FakeDockerClient{} ctx, cancel := context.WithCancel(context.Background()) cancel() @@ -183,6 +187,7 @@ func TestInstance_StartWithContext_Fails_Stop_AfterTest(t *testing.T) { } func TestInstance_Stop_Fails(t *testing.T) { + t.Parallel() f := &internalfakes.FakeDockerClient{} f.ContainerStopReturns(errors.New("can't stop")) i := &Instance{cli: f, log: logrus.StandardLogger(), containerId: "something"} @@ -190,7 +195,8 @@ func TestInstance_Stop_Fails(t *testing.T) { } func TestInstance_checkAvailable_Session_Fails(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) + t.Parallel() + ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) defer cancel() require.NoError(t, os.Setenv("AWS_STS_REGIONAL_ENDPOINTS", "FAILURE")) defer func() { @@ -201,6 +207,7 @@ func TestInstance_checkAvailable_Session_Fails(t *testing.T) { } func TestInstance_waitToBeAvailable_Context_Expired(t *testing.T) { + t.Parallel() ctx, cancel := context.WithCancel(context.Background()) cancel() i := &Instance{log: logrus.StandardLogger()}