fix(simple): add missing mapper constructor
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
84362d9dc5
commit
4a0213e89f
3 changed files with 31 additions and 5 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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{}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue