Skip to content

Commit

Permalink
♻️ Enable start of individual services via start
Browse files Browse the repository at this point in the history
Deprecate StartWithContext as shutdown is unreliable due to go routine firing to late
  • Loading branch information
elgohr committed Sep 12, 2023
1 parent 934b604 commit 43862b6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '^1.20'
go-version: '^1.21'
- uses: github/codeql-action/init@v2
with:
languages: 'go'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ on: push
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '^1.20'
go-version: '^1.21'
- name: Test
run: go test -race -timeout 20m -coverprofile=coverage.txt -covermode=atomic ./...
run: go test -race -timeout 30m -coverprofile=coverage.txt -covermode=atomic ./...
- name: Coverage
uses: codecov/codecov-action@v3
with:
Expand All @@ -26,5 +26,5 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '^1.20'
go-version: '^1.21'
- run: make install-release-tool new-patch-release
6 changes: 3 additions & 3 deletions localstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ func NewInstanceCtx(ctx context.Context, opts ...InstanceOption) (*Instance, err
}

// Start starts the localstack
func (i *Instance) Start() error {
return i.start(context.Background())
func (i *Instance) Start(services ...Service) error {
return i.start(context.Background(), services...)
}

// StartWithContext starts the localstack and ends it when the context is done.
// Use it to also start individual services, by default all are started.
// Deprecated: Use Start/Stop instead, as shutdown is not reliable
func (i *Instance) StartWithContext(ctx context.Context, services ...Service) error {
go func() {
<-ctx.Done()
Expand Down
29 changes: 28 additions & 1 deletion localstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,37 @@ func TestLocalStackWithIndividualServicesOnContext(t *testing.T) {
}
}
cancel()

// wait until service was shutdown
require.Eventually(t, func() bool {
_, err := cl.Get(l.EndpointV2(service))
return err != nil
}, time.Minute, 300*time.Millisecond)
})
}
}

func TestLocalStackWithIndividualServices(t *testing.T) {
cl := http.Client{Timeout: time.Second}
for service := range localstack.AvailableServices {
t.Run(service.Name, func(t *testing.T) {
l, err := localstack.NewInstance()
require.NoError(t, err)
require.NoError(t, l.Start(service))
for testService := range localstack.AvailableServices {
conn, err := net.DialTimeout("tcp", strings.TrimPrefix(l.EndpointV2(testService), "http://"), time.Second)
if testService == service || testService == localstack.DynamoDB {
require.NoError(t, err, testService)
require.NoError(t, conn.Close())
}
}
assert.NoError(t, l.Stop())

// wait until service was shutdown
require.Eventually(t, func() bool {
_, err := cl.Get(l.EndpointV2(service))
return err != nil
}, time.Minute, time.Second)
}, time.Minute, 300*time.Millisecond)
})
}
}
Expand Down

0 comments on commit 43862b6

Please sign in to comment.