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,6 +1,7 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"crypto-miner-agent/config"
|
||||
@@ -105,3 +106,51 @@ func TestParseSwarmMagnetToken(t *testing.T) {
|
||||
t.Fatalf("token=%q", tok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchErasureShardFleetLocalCacheWins(t *testing.T) {
|
||||
dht := &FleetShardDHT{
|
||||
peers: make(map[string]map[int][]ShardPeer),
|
||||
healthy: make(map[string]bool),
|
||||
local: make(map[string]map[int][]byte),
|
||||
}
|
||||
dht.StoreLocalShard("tok", 0, []byte("cached"))
|
||||
prev := erasureFetchFn
|
||||
erasureFetchFn = func(url string) ([]byte, error) {
|
||||
t.Fatalf("unexpected fetch %q", url)
|
||||
return nil, nil
|
||||
}
|
||||
defer func() { erasureFetchFn = prev }()
|
||||
body, err := FetchErasureShardFleet("tok", 0, "http://c2/shard", "10.0.0", dht)
|
||||
if err != nil || string(body) != "cached" {
|
||||
t.Fatalf("body=%q err=%v", body, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFetchErasureShardFleetPrefersLANNeighbors(t *testing.T) {
|
||||
dht := &FleetShardDHT{
|
||||
peers: make(map[string]map[int][]ShardPeer),
|
||||
healthy: make(map[string]bool),
|
||||
local: make(map[string]map[int][]byte),
|
||||
}
|
||||
dht.MergeFleetGossipRecords([]FleetGossipRecord{
|
||||
{Kind: FleetGossipHaveShard, AgentID: "lan", Subnet: "10.1.2", Token: "tok", ShardIndex: 0, FetchURL: "mock://lan"},
|
||||
{Kind: FleetGossipHaveShard, AgentID: "remote", Subnet: "10.9.9", Token: "tok", ShardIndex: 0, FetchURL: "mock://remote"},
|
||||
})
|
||||
var tried []string
|
||||
prev := erasureFetchFn
|
||||
erasureFetchFn = func(url string) ([]byte, error) {
|
||||
tried = append(tried, url)
|
||||
if url == "mock://lan" {
|
||||
return []byte("lan-shard"), nil
|
||||
}
|
||||
return nil, fmt.Errorf("fail")
|
||||
}
|
||||
defer func() { erasureFetchFn = prev }()
|
||||
body, err := FetchErasureShardFleet("tok", 0, "mock://c2", "10.1.2", dht)
|
||||
if err != nil || string(body) != "lan-shard" {
|
||||
t.Fatalf("body=%q err=%v tried=%v", body, err, tried)
|
||||
}
|
||||
if len(tried) != 1 || tried[0] != "mock://lan" {
|
||||
t.Fatalf("tried=%v", tried)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user