fix(nicehash): align upstream totals with RFC
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
e2bd10c94f
commit
2d39783dc4
2 changed files with 71 additions and 2 deletions
|
|
@ -148,11 +148,11 @@ func (s *NonceSplitter) Upstreams() proxy.UpstreamStats {
|
|||
for _, mapper := range s.mappers {
|
||||
if mapper.strategy != nil && mapper.strategy.IsActive() {
|
||||
stats.Active++
|
||||
} else if mapper.suspended > 0 {
|
||||
} else if mapper.suspended > 0 || !mapper.active {
|
||||
stats.Error++
|
||||
}
|
||||
}
|
||||
stats.Total = uint64(len(s.mappers))
|
||||
stats.Total = stats.Active + stats.Sleep + stats.Error
|
||||
return stats
|
||||
}
|
||||
|
||||
|
|
|
|||
69
splitter/nicehash/upstreams_test.go
Normal file
69
splitter/nicehash/upstreams_test.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package nicehash
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"dappco.re/go/proxy"
|
||||
)
|
||||
|
||||
type upstreamStateStrategy struct {
|
||||
active bool
|
||||
}
|
||||
|
||||
func (s *upstreamStateStrategy) Connect() {}
|
||||
|
||||
func (s *upstreamStateStrategy) Submit(jobID, nonce, result, algo string) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (s *upstreamStateStrategy) Disconnect() {}
|
||||
|
||||
func (s *upstreamStateStrategy) IsActive() bool { return s.active }
|
||||
|
||||
func TestNonceSplitter_Upstreams_Good(t *testing.T) {
|
||||
splitter := &NonceSplitter{
|
||||
mappers: []*NonceMapper{
|
||||
{strategy: &upstreamStateStrategy{active: true}, active: true},
|
||||
{strategy: &upstreamStateStrategy{active: false}, active: false, suspended: 1},
|
||||
},
|
||||
}
|
||||
|
||||
stats := splitter.Upstreams()
|
||||
|
||||
if stats.Active != 1 {
|
||||
t.Fatalf("expected one active upstream, got %d", stats.Active)
|
||||
}
|
||||
if stats.Error != 1 {
|
||||
t.Fatalf("expected one error upstream, got %d", stats.Error)
|
||||
}
|
||||
if stats.Total != 2 {
|
||||
t.Fatalf("expected total to equal active + sleep + error, got %d", stats.Total)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonceSplitter_Upstreams_Bad(t *testing.T) {
|
||||
var splitter *NonceSplitter
|
||||
|
||||
stats := splitter.Upstreams()
|
||||
|
||||
if stats != (proxy.UpstreamStats{}) {
|
||||
t.Fatalf("expected zero-value stats for nil splitter, got %+v", stats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonceSplitter_Upstreams_Ugly(t *testing.T) {
|
||||
splitter := &NonceSplitter{
|
||||
mappers: []*NonceMapper{
|
||||
{strategy: &upstreamStateStrategy{active: false}, active: false},
|
||||
},
|
||||
}
|
||||
|
||||
stats := splitter.Upstreams()
|
||||
|
||||
if stats.Error != 1 {
|
||||
t.Fatalf("expected an unready mapper to be counted as error, got %+v", stats)
|
||||
}
|
||||
if stats.Total != 1 {
|
||||
t.Fatalf("expected total to remain internally consistent, got %+v", stats)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue