Extend agent tests for cloud fleet features and erasure lanes.
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
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.
This commit is contained in:
@@ -1,3 +1,42 @@
|
||||
package client
|
||||
import "testing"
|
||||
func TestCloudVenueReportPayloadShape(t *testing.T){ t.Skip("covered") }
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-agent/deploy"
|
||||
)
|
||||
|
||||
func TestCloudVenueReportPayloadShape(t *testing.T) {
|
||||
probe := &deploy.CloudVenueProbe{
|
||||
CloudProvider: "aws",
|
||||
Environment: "prod",
|
||||
Workload: "gpu",
|
||||
InstanceType: "g4dn.xlarge",
|
||||
InstanceLifecycle: "spot",
|
||||
AvailabilityZone: "us-east-1a",
|
||||
OrganizationalUnit: "ou/GPU",
|
||||
EC2Tags: map[string]string{"Environment": "prod"},
|
||||
}
|
||||
payload := map[string]interface{}{
|
||||
"cloud_provider": probe.CloudProvider,
|
||||
"environment": probe.Environment,
|
||||
"workload": probe.Workload,
|
||||
"instance_type": probe.InstanceType,
|
||||
"instance_lifecycle": probe.InstanceLifecycle,
|
||||
"availability_zone": probe.AvailabilityZone,
|
||||
"organizational_unit": probe.OrganizationalUnit,
|
||||
"ec2_tags": probe.EC2Tags,
|
||||
}
|
||||
raw, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got map[string]interface{}
|
||||
if err := json.Unmarshal(raw, &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got["cloud_provider"] != "aws" || got["instance_type"] != "g4dn.xlarge" {
|
||||
t.Fatalf("payload=%v", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ func (c *AgentClient) applyEpidemiologyFixJSON(raw json.RawMessage) {
|
||||
if err := json.Unmarshal(raw, &fix); err != nil {
|
||||
return
|
||||
}
|
||||
if fix.AgentID != "" && fix.AgentID != c.agentID {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
policy := c.tierPolicy
|
||||
if len(fix.SkipTiers) > 0 {
|
||||
|
||||
@@ -4,11 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-agent/config"
|
||||
"crypto-miner-agent/miner"
|
||||
)
|
||||
|
||||
func TestApplyEpidemiologyFixSkipsFailedTiers(t *testing.T) {
|
||||
c := &AgentClient{}
|
||||
c := &AgentClient{agentID: "a1"}
|
||||
raw, _ := json.Marshal(EpidemiologyFix{
|
||||
AgentID: "a1",
|
||||
Reason: "broken branch",
|
||||
@@ -35,3 +36,25 @@ func TestApplyEpidemiologyFixForceTier(t *testing.T) {
|
||||
t.Fatalf("force tier=%v", policy.ForceTier)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyEpidemiologyFixErasureLanes(t *testing.T) {
|
||||
c := &AgentClient{cfg: config.RuntimeConfig{}}
|
||||
raw, _ := json.Marshal(EpidemiologyFix{ErasureLanes: true, Reason: "court splice"})
|
||||
c.applyEpidemiologyFixJSON(raw)
|
||||
if !c.cfg.ErasureLanesEnabled {
|
||||
t.Fatal("expected erasure lanes enabled")
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyEpidemiologyFixSkipsWrongAgent(t *testing.T) {
|
||||
c := &AgentClient{agentID: "mine", tierPolicy: miner.MiningTierPolicy{SkipTiers: []miner.LOTLTier{"wsl"}}}
|
||||
raw, _ := json.Marshal(EpidemiologyFix{
|
||||
AgentID: "other",
|
||||
SkipTiers: []string{"exe_subprocess"},
|
||||
})
|
||||
c.applyEpidemiologyFixJSON(raw)
|
||||
policy := c.miningTierPolicy()
|
||||
if len(policy.SkipTiers) != 1 || policy.SkipTiers[0] != miner.LOTLTier("wsl") {
|
||||
t.Fatalf("policy=%+v", policy)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,3 +48,19 @@ func TestParseMiningMethodOrder(t *testing.T) {
|
||||
t.Fatalf("order=%v", order)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelfSurgeryFallbackReorder(t *testing.T) {
|
||||
c := miningChainTestClient(t, config.RuntimeConfig{})
|
||||
c.miningChain = newTestMiningChainRunner(t, c)
|
||||
ok, detail := c.runSelfSurgeryAction("fallback_chain_reorder", MiningSelfSurgeryPlan{
|
||||
ChainOrder: []string{"inprocess", "container"},
|
||||
SkipMethods: []string{"gpu_subprocess"},
|
||||
})
|
||||
if !ok || detail == "" {
|
||||
t.Fatalf("ok=%v detail=%q", ok, detail)
|
||||
}
|
||||
st := c.miningChain.Status()
|
||||
if len(st.ChainOrder) != 2 || st.ChainOrder[0] != miner.MethodInProcess {
|
||||
t.Fatalf("chain=%v", st.ChainOrder)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user