From a96cd3fc3d8b4344c51c1c7ed8b820fff45af6c3 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 24 Jan 2022 09:57:21 -0600 Subject: [PATCH] ci: Run peer tests faster on local machine (#54) This should result in faster local development, and faster CI! See the code comment for rationale. --- peer/conn_test.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/peer/conn_test.go b/peer/conn_test.go index ab6cd9044c..29ec872a9f 100644 --- a/peer/conn_test.go +++ b/peer/conn_test.go @@ -6,6 +6,7 @@ import ( "io" "net" "net/http" + "os" "sync" "testing" "time" @@ -22,13 +23,25 @@ import ( "github.com/coder/coder/peer" ) -const ( - disconnectedTimeout = 5 * time.Second - failedTimeout = disconnectedTimeout * 5 - keepAliveInterval = time.Millisecond * 2 -) - var ( + disconnectedTimeout = func() time.Duration { + // Connection state is unfortunately time-based. When resources are + // contended, a connection can take greater than this timeout to + // handshake, which results in a test flake. + // + // During local testing resources are rarely contended. Reducing this + // timeout leads to faster local development. + // + // In CI resources are frequently contended, so increasing this value + // results in less flakes. + if os.Getenv("CI") == "true" { + return 4 * time.Second + } + return 100 * time.Millisecond + }() + failedTimeout = disconnectedTimeout * 4 + keepAliveInterval = time.Millisecond * 2 + // There's a global race in the vnet library allocation code. // This mutex locks around the creation of the vnet. vnetMutex = sync.Mutex{}