Fix flaky stats-batch tests and extend Crucible E2E LOTL coverage.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled

Stop the stats batch timer in unit tests before reading pending coalesced state, teach the Playwright stub agent to emit lotl_tier stats, and prefer server/webroot so phase-8 E2E serves the current frontend build.
This commit is contained in:
AetherForge
2026-06-07 00:52:55 -07:00
parent fd5cc1dd61
commit e37eb24369
8 changed files with 85 additions and 17 deletions

View File

@@ -683,6 +683,8 @@ func TestMiningStatusRelayCoalescedToStatsBatch(t *testing.T) {
if err := connB.WriteJSON(Message{Type: "mining_fallback", Payload: payloadB}); err != nil {
t.Fatal(err)
}
stopStatsBatchTimer(hub)
hub.flushStatsBatch()
select {
case r := <-batchCh:
@@ -721,6 +723,17 @@ func TestMiningStatusRelayCoalescedToStatsBatch(t *testing.T) {
}
}
// stopStatsBatchTimer cancels the 250ms flush timer so tests can read statsBatch
// without racing flushStatsBatch clearing the pending map.
func stopStatsBatchTimer(hub *WSHub) {
hub.statsBatchMu.Lock()
defer hub.statsBatchMu.Unlock()
if hub.statsBatchTimer != nil {
hub.statsBatchTimer.Stop()
hub.statsBatchTimer = nil
}
}
func TestStatsBatchCoalescesSameAgent(t *testing.T) {
hub := NewWSHub(nil)
hub.queueStatsBroadcast(map[string]interface{}{
@@ -729,11 +742,13 @@ func TestStatsBatchCoalescesSameAgent(t *testing.T) {
hub.queueStatsBroadcast(map[string]interface{}{
"agent_id": "a1", "hashrate_15s": 99.0, "active_method": "inprocess",
})
stopStatsBatchTimer(hub)
hub.flushStatsBatch()
// Merged coalesce — later keys overwrite, earlier keys preserved.
hub.queueStatsBroadcast(map[string]interface{}{"agent_id": "a1", "hashrate_15s": 10.0, "lotl_tier": "cpu_inprocess"})
hub.queueStatsBroadcast(map[string]interface{}{"agent_id": "a1", "mining_hashrate": 850.0})
stopStatsBatchTimer(hub)
hub.statsBatchMu.Lock()
if len(hub.statsBatch) != 1 {
t.Fatalf("expected 1 agent in batch map, got %d", len(hub.statsBatch))
@@ -755,6 +770,7 @@ func TestStatsBatchCoalescesSameAgent(t *testing.T) {
hub.queueStatsBroadcast(map[string]interface{}{"agent_id": "a1", "hashrate_15s": 1.0})
hub.queueStatsBroadcast(map[string]interface{}{"agent_id": "a1", "hashrate_15s": 2.0})
stopStatsBatchTimer(hub)
hub.statsBatchMu.Lock()
if len(hub.statsBatch) != 1 {
t.Fatalf("expected 1 agent in batch map, got %d", len(hub.statsBatch))
@@ -780,6 +796,7 @@ func TestStatsBatchCoalescesLotlAttempts(t *testing.T) {
},
})
hub.queueStatsBroadcast(map[string]interface{}{"agent_id": "a2", "mining_hashrate": 1200.0})
stopStatsBatchTimer(hub)
hub.statsBatchMu.Lock()
var merged map[string]interface{}
if err := json.Unmarshal(hub.statsBatch["a2"], &merged); err != nil {