mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-21 17:07:47 +02:00
test: wait for hub setup in universal token integration test
This commit is contained in:
@@ -1149,42 +1149,43 @@ func TestMultipleSystemsWithSameUniversalToken(t *testing.T) {
|
|||||||
|
|
||||||
// Verify system creation/reuse behavior
|
// Verify system creation/reuse behavior
|
||||||
if tc.expectConnection {
|
if tc.expectConnection {
|
||||||
// Count systems after connection
|
expectedSystemsAfter := systemsBeforeCount
|
||||||
systemsAfter, err := testApp.FindRecordsByFilter("systems", "users ~ {:userId}", "", -1, 0, map[string]any{"userId": userRecord.Id})
|
|
||||||
require.NoError(t, err)
|
|
||||||
systemsAfterCount := len(systemsAfter)
|
|
||||||
|
|
||||||
if tc.expectNewSystem {
|
if tc.expectNewSystem {
|
||||||
// Should have created a new system
|
expectedSystemsAfter++
|
||||||
systemCount++
|
systemCount++
|
||||||
assert.Equal(t, systemsBeforeCount+1, systemsAfterCount, "Should have created a new system")
|
|
||||||
assert.Equal(t, systemCount, systemsAfterCount, "Total system count should match expected")
|
|
||||||
} else {
|
|
||||||
// Should have reused existing system
|
|
||||||
assert.Equal(t, systemsBeforeCount, systemsAfterCount, "Should not have created a new system")
|
|
||||||
assert.Equal(t, systemCount, systemsAfterCount, "Total system count should remain the same")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(20 * time.Millisecond)
|
// WebSocket connection precedes the hub's asynchronous system
|
||||||
|
// setup. Re-read all database state until setup is complete.
|
||||||
|
var systemId, status string
|
||||||
|
require.EventuallyWithT(t, func(c *assert.CollectT) {
|
||||||
|
systemsAfter, err := testApp.FindRecordsByFilter("systems", "users ~ {:userId}", "", -1, 0, map[string]any{"userId": userRecord.Id})
|
||||||
|
if !assert.NoError(c, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.Len(c, systemsAfter, expectedSystemsAfter, "System creation/reuse should match expected behavior")
|
||||||
|
assert.Len(c, systemsAfter, systemCount, "Total system count should match expected")
|
||||||
|
|
||||||
// Verify that a fingerprint record exists for this fingerprint
|
fingerprints, err := testApp.FindRecordsByFilter("fingerprints", "token = {:token} && fingerprint = {:fingerprint}", "", -1, 0, map[string]any{
|
||||||
fingerprints, err := testApp.FindRecordsByFilter("fingerprints", "token = {:token} && fingerprint = {:fingerprint}", "", -1, 0, map[string]any{
|
"token": universalToken,
|
||||||
"token": universalToken,
|
"fingerprint": tc.agentFingerprint,
|
||||||
"fingerprint": tc.agentFingerprint,
|
})
|
||||||
})
|
if !assert.NoError(c, err) || !assert.Len(c, fingerprints, 1, "Should have exactly one fingerprint record for this token+fingerprint combination") {
|
||||||
require.NoError(t, err)
|
return
|
||||||
require.Len(t, fingerprints, 1, "Should have exactly one fingerprint record for this token+fingerprint combination")
|
}
|
||||||
|
|
||||||
fingerprint := fingerprints[0]
|
fingerprint := fingerprints[0]
|
||||||
assert.Equal(t, universalToken, fingerprint.GetString("token"), "Fingerprint should have the universal token")
|
assert.Equal(c, universalToken, fingerprint.GetString("token"), "Fingerprint should have the universal token")
|
||||||
assert.Equal(t, tc.agentFingerprint, fingerprint.GetString("fingerprint"), "Fingerprint should match agent's fingerprint")
|
assert.Equal(c, tc.agentFingerprint, fingerprint.GetString("fingerprint"), "Fingerprint should match agent's fingerprint")
|
||||||
|
|
||||||
// Verify system status
|
systemId = fingerprint.GetString("system")
|
||||||
systemId := fingerprint.GetString("system")
|
system, err := testApp.FindRecordById("systems", systemId)
|
||||||
system, err := testApp.FindRecordById("systems", systemId)
|
if !assert.NoError(c, err) {
|
||||||
require.NoError(t, err)
|
return
|
||||||
status := system.GetString("status")
|
}
|
||||||
assert.Equal(t, tc.expectSystemStatus, status, "System status should match expected value")
|
status = system.GetString("status")
|
||||||
|
assert.Equal(c, tc.expectSystemStatus, status, "System status should match expected value")
|
||||||
|
}, 5*time.Second, 20*time.Millisecond)
|
||||||
|
|
||||||
t.Logf("%s - System ID: %s, Status: %s, New System: %v", tc.description, systemId, status, tc.expectNewSystem)
|
t.Logf("%s - System ID: %s, Status: %s, New System: %v", tc.description, systemId, status, tc.expectNewSystem)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user