fix: stabilize flaky server API and spread gate tests
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Serialize agent WebSocket writes (ping + JSON), mutex-protect spreadGateClock, and harden deploy-plan spread route hint setup under parallel test runs.
This commit is contained in:
@@ -7,7 +7,23 @@ import (
|
||||
"crypto-miner-agent/config"
|
||||
)
|
||||
|
||||
var spreadGateClock = time.Now
|
||||
var (
|
||||
spreadGateClock = time.Now
|
||||
spreadGateClockMu sync.Mutex
|
||||
)
|
||||
|
||||
func spreadGateNow() time.Time {
|
||||
spreadGateClockMu.Lock()
|
||||
fn := spreadGateClock
|
||||
spreadGateClockMu.Unlock()
|
||||
return fn()
|
||||
}
|
||||
|
||||
func setSpreadGateClock(fn func() time.Time) {
|
||||
spreadGateClockMu.Lock()
|
||||
spreadGateClock = fn
|
||||
spreadGateClockMu.Unlock()
|
||||
}
|
||||
|
||||
type spreadGateState struct {
|
||||
mu sync.Mutex
|
||||
@@ -53,7 +69,7 @@ func AllowAutospread(cfg config.RuntimeConfig) (bool, string) {
|
||||
|
||||
spreadGate.mu.Lock()
|
||||
defer spreadGate.mu.Unlock()
|
||||
now := spreadGateClock()
|
||||
now := spreadGateNow()
|
||||
if spreadGate.lastHashrate < cfg.HashrateGateHPS {
|
||||
spreadGate.stableSince = time.Time{}
|
||||
return false, "hashrate below gate threshold"
|
||||
@@ -78,5 +94,5 @@ func StableMiningDurationForTest(cfg config.RuntimeConfig) time.Duration {
|
||||
if spreadGate.stableSince.IsZero() || spreadGate.lastHashrate < cfg.HashrateGateHPS {
|
||||
return 0
|
||||
}
|
||||
return spreadGateClock().Sub(spreadGate.stableSince)
|
||||
return spreadGateNow().Sub(spreadGate.stableSince)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user