Fleet topology epidemiology: strain plague map, interrupt fixes, 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
This commit is contained in:
61
server/internal/api/epidemiology_test.go
Normal file
61
server/internal/api/epidemiology_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-server/internal/epidemiology"
|
||||
)
|
||||
|
||||
func TestEpidemiologyAuthFixOneShot(t *testing.T) {
|
||||
hub := NewWSHub(nil)
|
||||
hub.WireDefaultEpidemiologyReporter()
|
||||
|
||||
hub.observeEpidemiologyFromStats("agent-fix", epidemiology.StatsInput{
|
||||
ChainExhausted: true,
|
||||
SpreadStrain: "#aabbcc",
|
||||
FailedMethods: []epidemiology.MethodFailure{
|
||||
{Method: "exe_subprocess", Reason: "blocked"},
|
||||
},
|
||||
})
|
||||
|
||||
resp := map[string]interface{}{}
|
||||
hub.attachEpidemiologyFix(resp, "agent-fix")
|
||||
if _, ok := resp["epidemiology_fix"]; !ok {
|
||||
t.Fatal("expected epidemiology_fix on auth pass")
|
||||
}
|
||||
raw, _ := json.Marshal(resp["epidemiology_fix"])
|
||||
var fix epidemiology.AgentFix
|
||||
if err := json.Unmarshal(raw, &fix); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if fix.AgentID != "agent-fix" || !fix.RestartChain {
|
||||
t.Fatalf("fix=%+v", fix)
|
||||
}
|
||||
|
||||
resp2 := map[string]interface{}{}
|
||||
hub.attachEpidemiologyFix(resp2, "agent-fix")
|
||||
if _, ok := resp2["epidemiology_fix"]; ok {
|
||||
t.Fatal("fix should be consumed after first auth pass")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEpidemiologySeerEventBroadcast(t *testing.T) {
|
||||
hub := NewWSHub(nil)
|
||||
var seerKind string
|
||||
hub.SetEpidemiologyReporter(epidemiology.Reporter{
|
||||
OnSeer: func(ev epidemiology.SeerEvent) {
|
||||
seerKind = ev.Kind
|
||||
hub.broadcastSeerEvent(ev)
|
||||
},
|
||||
})
|
||||
hub.observeEpidemiologyFromStats("seer-agent", epidemiology.StatsInput{
|
||||
ChainExhausted: true,
|
||||
FailedMethods: []epidemiology.MethodFailure{
|
||||
{Method: "container", Reason: "no runtime"},
|
||||
},
|
||||
})
|
||||
if seerKind != "mining_interrupt" {
|
||||
t.Fatalf("seer kind=%q", seerKind)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user