mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-12 04:39:05 +02:00
tests: fix flaky unit test
This commit is contained in:
@@ -5,7 +5,6 @@ package devicelogin
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -236,6 +235,7 @@ func TestPendingExchangeObservesDecisionDuringLongPoll(t *testing.T) {
|
||||
require.True(t, apperror.IsCode(outcome.err, apperror.CodeDeviceLoginDenied))
|
||||
require.Equal(t, RequestStatusDenied, outcome.status)
|
||||
case <-time.After(2 * time.Second):
|
||||
case <-time.After(actorPollingInterval + 5*time.Second):
|
||||
t.Fatal("exchange did not observe the actor decision")
|
||||
}
|
||||
}
|
||||
@@ -548,7 +548,7 @@ func startPersistentDeviceLoginHost(t *testing.T, db *gorm.DB, deps Dependencies
|
||||
require.NoError(t, err)
|
||||
|
||||
host, err := local.NewHost(
|
||||
local.WithAddress(freeLoopbackAddress(t)),
|
||||
local.WithAddress(testutils.FreeLoopbackUDPAddr(t)),
|
||||
local.WithRuntimePSKs([]byte("pocket-id-device-login-test-host-psk")),
|
||||
local.WithSQLiteProvider(local.SQLiteProviderOptions{DB: sqlDB}),
|
||||
local.WithShutdownGracePeriod(time.Second),
|
||||
@@ -587,16 +587,6 @@ func startPersistentDeviceLoginHost(t *testing.T, db *gorm.DB, deps Dependencies
|
||||
return module, stop
|
||||
}
|
||||
|
||||
func freeLoopbackAddress(t *testing.T) string {
|
||||
t.Helper()
|
||||
var listenConfig net.ListenConfig
|
||||
listener, err := listenConfig.Listen(t.Context(), "tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
address := listener.Addr().String()
|
||||
require.NoError(t, listener.Close())
|
||||
return address
|
||||
}
|
||||
|
||||
func (f *fakeAuditLogger) CreateSignIn(ctx context.Context, event auditlogs.Event, ipAddress, userAgent, userID, browserToken string, tx *gorm.DB, mode appconfig.AppConfigValue) auditlogs.SignInResult {
|
||||
entry, created := f.Create(ctx, event, ipAddress, userAgent, userID, auditlogs.Data{}, tx)
|
||||
entry.Event = event
|
||||
|
||||
@@ -31,7 +31,7 @@ const testActorHostPSK = "pocket-id-test-actor-host-psk-32bytes"
|
||||
func NewActorHostForTest(t *testing.T, register func(t *testing.T, h *local.Host), extraOpts ...local.HostOption) *local.Host {
|
||||
t.Helper()
|
||||
|
||||
address := freeLoopbackUDPAddr(t)
|
||||
address := FreeLoopbackUDPAddr(t)
|
||||
hostOpts := []local.HostOption{
|
||||
local.WithAddress(address),
|
||||
local.WithRuntimePSKs([]byte(testActorHostPSK)),
|
||||
@@ -111,9 +111,9 @@ func waitForActorHostPeerServer(t *testing.T, address string, errCh <-chan error
|
||||
t.Fatalf("timed out waiting for actor host peer server %s", address)
|
||||
}
|
||||
|
||||
// freeLoopbackUDPAddr reserves a free loopback UDP port and returns its address
|
||||
// FreeLoopbackUDPAddr reserves a free loopback UDP port and returns its address
|
||||
// The port is released before returning, so the actor host can bind it
|
||||
func freeLoopbackUDPAddr(t *testing.T) string {
|
||||
func FreeLoopbackUDPAddr(t *testing.T) string {
|
||||
t.Helper()
|
||||
|
||||
var lc net.ListenConfig
|
||||
|
||||
Reference in New Issue
Block a user