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.
This commit is contained in:
Kyle Carberry 2022-01-24 09:57:21 -06:00 committed by GitHub
parent 8be245616a
commit a96cd3fc3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 6 deletions

View File

@ -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{}