Skip to content

Commit a96cd3f

Browse files
authored
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.
1 parent 8be2456 commit a96cd3f

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

peer/conn_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"net"
88
"net/http"
9+
"os"
910
"sync"
1011
"testing"
1112
"time"
@@ -22,13 +23,25 @@ import (
2223
"github.com/coder/coder/peer"
2324
)
2425

25-
const (
26-
disconnectedTimeout = 5 * time.Second
27-
failedTimeout = disconnectedTimeout * 5
28-
keepAliveInterval = time.Millisecond * 2
29-
)
30-
3126
var (
27+
disconnectedTimeout = func() time.Duration {
28+
// Connection state is unfortunately time-based. When resources are
29+
// contended, a connection can take greater than this timeout to
30+
// handshake, which results in a test flake.
31+
//
32+
// During local testing resources are rarely contended. Reducing this
33+
// timeout leads to faster local development.
34+
//
35+
// In CI resources are frequently contended, so increasing this value
36+
// results in less flakes.
37+
if os.Getenv("CI") == "true" {
38+
return 4 * time.Second
39+
}
40+
return 100 * time.Millisecond
41+
}()
42+
failedTimeout = disconnectedTimeout * 4
43+
keepAliveInterval = time.Millisecond * 2
44+
3245
// There's a global race in the vnet library allocation code.
3346
// This mutex locks around the creation of the vnet.
3447
vnetMutex = sync.Mutex{}

0 commit comments

Comments
 (0)