Skip to content

Commit

Permalink
Fixes failing TestPeerInfoApi test on windows (#4888)
Browse files Browse the repository at this point in the history
## Motivation
This fixes the `TestPeerInfoApi` test currently failing on our windows CI run.

## Changes
Moved the call to `t.Cleanup` to close apps to be after any call to `t.TempDir` used to setup apps, this ensures that we first close apps, and then delete their temp dirs as opposed to vice-versa.

## Test Plan
See that `TestPeerInfoApi` passes on the windows CI run.
  • Loading branch information
piersy committed Aug 22, 2023
1 parent 5a90e8d commit 264e589
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions node/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ func NewTestNetwork(t *testing.T, conf config.Config, l log.Log, size int) []*Te
g, grpContext := errgroup.WithContext(ctx)
var apps []*TestApp

t.Cleanup(func() {
cancel()
// Wait for nodes to shutdown
g.Wait()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
for _, a := range apps {
a.Cleanup(ctx)
}
})

for i := 0; i < size; i++ {
// Copy config, services don't modify their config, so we just need to
// be careful here when we modify any pointer values in the config.
Expand Down Expand Up @@ -83,6 +71,23 @@ func NewTestNetwork(t *testing.T, conf config.Config, l log.Log, size int) []*Te
apps = append(apps, &TestApp{app, conn})
}

// Note that we must call cleanup after all calls to t.TempDir since calls
// to cleanup are executed in LIFO fashion (similar to defer) and t.TempDir
// internally calls Cleanup to delete the dir. By calling Cleanup here
// we ensure that the apps have been shut-down before attempting to delete
// the temp dirs.
t.Cleanup(func() {
cancel()
// Wait for nodes to shutdown
g.Wait()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
for _, a := range apps {
a.Cleanup(ctx)
}
})

// Connect all nodes to each other
for i := 0; i < size; i++ {
for j := i + 1; j < size; j++ {
Expand Down

0 comments on commit 264e589

Please sign in to comment.