From b35714a7835995cf0fa96bf1a3918ef06f1f386d Mon Sep 17 00:00:00 2001 From: Josh Berry Date: Thu, 19 Oct 2023 15:23:59 -0700 Subject: [PATCH 1/2] Fix sources of test instability - Wait up to 10 seconds for the server to become healthy before assuming it's failed. After the server starts accepting connections, we were assuming it should be healthy immediately, but that's not always true. - Make sure the server finishes shutting down before exiting the CLI, because otherwise it will hold open files, and this intermittently breaks tests on Windows (which, unlike POSIXy OSes, will refuse to delete open files). Closes #338. I hope. --- app/app_test.go | 12 ++++++++++-- server/commands.go | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/app_test.go b/app/app_test.go index babb908f..b62bb57f 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -320,8 +320,16 @@ func assertServerHealth(ctx context.Context, t *testing.T, opts sdkclient.Option t.Error(clientErr) } - if _, err := c.CheckHealth(ctx, nil); err != nil { - t.Error(err) + // Give the server 10 seconds to become healthy. + for i := 0; i < 10; i++ { + _, clientErr = c.CheckHealth(ctx, nil) + if clientErr == nil { + break + } + time.Sleep(100 * time.Millisecond) + } + if clientErr != nil { + t.Error(clientErr) } // Check for pollers on a system task queue to ensure that the worker service is running. diff --git a/server/commands.go b/server/commands.go index 5a1d45f4..9c20de4e 100644 --- a/server/commands.go +++ b/server/commands.go @@ -337,6 +337,7 @@ func NewServerCommands(defaultCfg *sconfig.Config) []*cli.Command { if err := s.Start(); err != nil { return cli.Exit(fmt.Sprintf("Unable to start server. Error: %v", err), 1) } + s.Stop() return cli.Exit("All services are stopped.", 0) }, }, From aa5b3bb63cdcc99a00798794869c6c6d6b656a11 Mon Sep 17 00:00:00 2001 From: Josh Berry Date: Thu, 19 Oct 2023 16:08:40 -0700 Subject: [PATCH 2/2] 100ms * 10 = 1 second, not 10 seconds. I swear I can do math. --- app/app_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app_test.go b/app/app_test.go index b62bb57f..026bbec3 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -320,7 +320,7 @@ func assertServerHealth(ctx context.Context, t *testing.T, opts sdkclient.Option t.Error(clientErr) } - // Give the server 10 seconds to become healthy. + // Give the server 1 second to become healthy. for i := 0; i < 10; i++ { _, clientErr = c.CheckHealth(ctx, nil) if clientErr == nil {