From 4a0213e89fe8d10f37fe9b263bd353e4910fcfe1 Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 22:57:19 +0000 Subject: [PATCH] fix(simple): add missing mapper constructor Co-Authored-By: Virgil --- splitter/simple/impl.go | 7 ++----- splitter/simple/impl_test.go | 18 ++++++++++++++++++ splitter/simple/mapper.go | 11 +++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/splitter/simple/impl.go b/splitter/simple/impl.go index b50b205..4fb2d41 100644 --- a/splitter/simple/impl.go +++ b/splitter/simple/impl.go @@ -248,11 +248,8 @@ func (s *SimpleSplitter) ReloadPools() { func (s *SimpleSplitter) newMapperLocked() *SimpleMapper { id := s.seq s.seq++ - mapper := &SimpleMapper{ - id: id, - events: s.events, - pending: make(map[int64]submitContext), - } + mapper := NewSimpleMapper(id, nil) + mapper.events = s.events mapper.strategy = s.factory(mapper) if mapper.strategy == nil { mapper.strategy = s.factory(mapper) diff --git a/splitter/simple/impl_test.go b/splitter/simple/impl_test.go index 02ce74a..2ce5f89 100644 --- a/splitter/simple/impl_test.go +++ b/splitter/simple/impl_test.go @@ -20,6 +20,24 @@ func (a activeStrategy) Submit(string, string, string, string) int64 { return 0 func (a activeStrategy) Disconnect() {} func (a activeStrategy) IsActive() bool { return true } +func TestSimpleMapper_New_Good(t *testing.T) { + strategy := activeStrategy{} + mapper := NewSimpleMapper(7, strategy) + + if mapper == nil { + t.Fatal("expected mapper") + } + if mapper.id != 7 { + t.Fatalf("expected mapper id 7, got %d", mapper.id) + } + if mapper.strategy != strategy { + t.Fatalf("expected strategy to be stored") + } + if mapper.pending == nil { + t.Fatal("expected pending map to be initialised") + } +} + func TestSimpleSplitter_OnLogin_Good(t *testing.T) { splitter := NewSimpleSplitter(&proxy.Config{ReuseTimeout: 30}, nil, func(listener pool.StratumListener) pool.Strategy { return activeStrategy{} diff --git a/splitter/simple/mapper.go b/splitter/simple/mapper.go index a37ebca..3fd4f2b 100644 --- a/splitter/simple/mapper.go +++ b/splitter/simple/mapper.go @@ -31,3 +31,14 @@ type submitContext struct { StartedAt time.Time JobID string } + +// NewSimpleMapper creates a passthrough mapper for one pool connection. +// +// m := simple.NewSimpleMapper(7, strategy) +func NewSimpleMapper(id int64, strategy pool.Strategy) *SimpleMapper { + return &SimpleMapper{ + id: id, + strategy: strategy, + pending: make(map[int64]submitContext), + } +}