Preserve bind addresses on reload and track active miners per Proxy instance. Co-Authored-By: Virgil <virgil@lethean.io>
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package proxy
|
|
|
|
import "testing"
|
|
|
|
func TestProxy_Reload_Good(t *testing.T) {
|
|
cfg := &Config{
|
|
Mode: "noop",
|
|
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
|
|
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
|
|
CustomDiff: 100,
|
|
Workers: WorkersDisabled,
|
|
}
|
|
proxyValue, errorValue := New(cfg)
|
|
if errorValue != nil {
|
|
t.Fatal(errorValue)
|
|
}
|
|
|
|
reloadCfg := &Config{
|
|
Mode: "simple",
|
|
Bind: []BindAddr{{Host: "0.0.0.0", Port: 4444}},
|
|
Pools: []PoolConfig{{URL: "pool-b:4444", Enabled: true}},
|
|
CustomDiff: 250,
|
|
Workers: WorkersByUser,
|
|
}
|
|
|
|
proxyValue.Reload(reloadCfg)
|
|
|
|
if len(proxyValue.config.Bind) != 1 || proxyValue.config.Bind[0].Port != 3333 {
|
|
t.Fatalf("expected bind addresses to remain unchanged, got %+v", proxyValue.config.Bind)
|
|
}
|
|
if len(proxyValue.config.Pools) != 1 || proxyValue.config.Pools[0].URL != "pool-b:4444" {
|
|
t.Fatalf("expected pools to reload, got %+v", proxyValue.config.Pools)
|
|
}
|
|
if proxyValue.config.CustomDiff != 250 {
|
|
t.Fatalf("expected custom diff to reload, got %d", proxyValue.config.CustomDiff)
|
|
}
|
|
if proxyValue.customDiff == nil || proxyValue.customDiff.globalDiff != 250 {
|
|
t.Fatalf("expected live custom diff to update, got %+v", proxyValue.customDiff)
|
|
}
|
|
}
|
|
|
|
func TestProxy_CurrentMiners_Good(t *testing.T) {
|
|
cfg := &Config{
|
|
Mode: "noop",
|
|
Bind: []BindAddr{{Host: "127.0.0.1", Port: 3333}},
|
|
Pools: []PoolConfig{{URL: "pool-a:3333", Enabled: true}},
|
|
Workers: WorkersDisabled,
|
|
}
|
|
firstProxy, errorValue := New(cfg)
|
|
if errorValue != nil {
|
|
t.Fatal(errorValue)
|
|
}
|
|
secondProxy, errorValue := New(cfg)
|
|
if errorValue != nil {
|
|
t.Fatal(errorValue)
|
|
}
|
|
|
|
miner := &Miner{}
|
|
firstProxy.events.Dispatch(Event{Type: EventLogin, Miner: miner})
|
|
if got := firstProxy.CurrentMiners(); got != 1 {
|
|
t.Fatalf("expected first proxy miner count 1, got %d", got)
|
|
}
|
|
if got := secondProxy.CurrentMiners(); got != 0 {
|
|
t.Fatalf("expected second proxy miner count 0, got %d", got)
|
|
}
|
|
|
|
firstProxy.events.Dispatch(Event{Type: EventClose, Miner: miner})
|
|
if got := firstProxy.CurrentMiners(); got != 0 {
|
|
t.Fatalf("expected first proxy miner count to return to 0, got %d", got)
|
|
}
|
|
}
|