Expand P2 test coverage: mining chain, spread lanes, path forge, WS/beacon, E2E onion, file handling
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:
80
agent/client/atlas_gossip_test.go
Normal file
80
agent/client/atlas_gossip_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-agent/config"
|
||||
"crypto-miner-agent/miner"
|
||||
)
|
||||
|
||||
func TestApplyGossipHintsMergesIntoPolicy(t *testing.T) {
|
||||
c := NewAgentClient(config.RuntimeConfig{})
|
||||
c.applyGossipHints([]AtlasSkip{
|
||||
{Tier: "docker", Condition: "no_docker", Reason: "lan sibling"},
|
||||
{Tier: "docker", Condition: "no_docker", Reason: "dup"},
|
||||
{Tier: "wsl", Condition: "defender_on", Reason: "blocked"},
|
||||
})
|
||||
|
||||
skips := c.atlasSkipsSnapshot()
|
||||
if len(skips) != 2 {
|
||||
t.Fatalf("atlasSkips=%+v", skips)
|
||||
}
|
||||
|
||||
policy := c.miningTierPolicy()
|
||||
have := map[miner.LOTLTier]bool{}
|
||||
for _, tier := range policy.SkipTiers {
|
||||
have[tier] = true
|
||||
}
|
||||
if !have[miner.LOTLTier("docker")] || !have[miner.LOTLTier("wsl")] {
|
||||
t.Fatalf("skip tiers=%v", policy.SkipTiers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleAtlasGossipMessage(t *testing.T) {
|
||||
c := NewAgentClient(config.RuntimeConfig{})
|
||||
payload, _ := json.Marshal(map[string]interface{}{
|
||||
"hints": []AtlasSkip{{Tier: "container", Condition: "defender_on", Reason: "relay"}},
|
||||
})
|
||||
c.handleAtlasGossip(payload)
|
||||
skips := c.atlasSkipsSnapshot()
|
||||
if len(skips) != 1 || skips[0].Tier != "container" {
|
||||
t.Fatalf("skips=%+v", skips)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaybeGossipFromAttemptsDedupes(t *testing.T) {
|
||||
c := NewAgentClient(config.RuntimeConfig{})
|
||||
c.setAtlasLanGossipEnabled(true)
|
||||
defFalse := false
|
||||
attempts := []TierAttemptPayload{{Tier: "docker", OK: false, Error: "denied"}}
|
||||
|
||||
c.maybeGossipFromAttempts(attempts, &defFalse)
|
||||
if len(c.gossipSent) != 1 {
|
||||
t.Fatalf("gossipSent=%v", c.gossipSent)
|
||||
}
|
||||
|
||||
before := len(c.gossipSent)
|
||||
c.maybeGossipFromAttempts(attempts, &defFalse)
|
||||
if len(c.gossipSent) != before {
|
||||
t.Fatal("duplicate attempt should not expand gossipSent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaybeGossipDisabledNoOp(t *testing.T) {
|
||||
c := NewAgentClient(config.RuntimeConfig{})
|
||||
c.setAtlasLanGossipEnabled(false)
|
||||
defTrue := true
|
||||
c.maybeGossipFromAttempts([]TierAttemptPayload{{Tier: "wsl", OK: false}}, &defTrue)
|
||||
if len(c.gossipSent) != 0 {
|
||||
t.Fatalf("gossipSent=%v want empty", c.gossipSent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyAuthLotlPolicySetsGossipFlag(t *testing.T) {
|
||||
c := NewAgentClient(config.RuntimeConfig{})
|
||||
c.applyAuthLotlPolicy(AuthResponse{AtlasLanGossipEnabled: true})
|
||||
if !c.atlasLanGossipEnabledSnapshot() {
|
||||
t.Fatal("expected atlas LAN gossip enabled from auth")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user