diff --git a/internal/account/pool_acquire.go b/internal/account/pool_acquire.go index b0c548c..6d1ec7d 100644 --- a/internal/account/pool_acquire.go +++ b/internal/account/pool_acquire.go @@ -60,16 +60,10 @@ func (p *Pool) acquireLocked(target string, exclude map[string]bool) (config.Acc return acc, true } - if acc, ok := p.tryAcquire(exclude, true); ok { - return acc, true - } - if acc, ok := p.tryAcquire(exclude, false); ok { - return acc, true - } - return config.Account{}, false + return p.tryAcquire(exclude) } -func (p *Pool) tryAcquire(exclude map[string]bool, requireToken bool) (config.Account, bool) { +func (p *Pool) tryAcquire(exclude map[string]bool) (config.Account, bool) { for i := 0; i < len(p.queue); i++ { id := p.queue[i] if exclude[id] || !p.canAcquireIDLocked(id) { @@ -79,9 +73,6 @@ func (p *Pool) tryAcquire(exclude map[string]bool, requireToken bool) (config.Ac if !ok { continue } - if requireToken && acc.Token == "" { - continue - } p.inUse[id]++ p.bumpQueue(id) return acc, true diff --git a/internal/account/pool_test.go b/internal/account/pool_test.go index 37109ff..89bef64 100644 --- a/internal/account/pool_test.go +++ b/internal/account/pool_test.go @@ -215,6 +215,33 @@ func TestPoolDropsLegacyTokenOnlyAccountOnLoad(t *testing.T) { } } +func TestPoolAcquireRotatesIntoTokenlessAccounts(t *testing.T) { + t.Setenv("DS2API_ACCOUNT_MAX_INFLIGHT", "1") + t.Setenv("DS2API_ACCOUNT_CONCURRENCY", "") + t.Setenv("DS2API_ACCOUNT_MAX_QUEUE", "") + t.Setenv("DS2API_ACCOUNT_QUEUE_SIZE", "") + t.Setenv("DS2API_CONFIG_JSON", `{ + "keys":["k1"], + "accounts":[ + {"email":"acc1@example.com","token":"token1"}, + {"email":"acc2@example.com","token":""}, + {"email":"acc3@example.com","token":""} + ] + }`) + + pool := NewPool(config.LoadStore()) + for i, want := range []string{"acc1@example.com", "acc2@example.com", "acc3@example.com"} { + acc, ok := pool.Acquire("", nil) + if !ok { + t.Fatalf("expected acquire success at step %d", i+1) + } + if got := acc.Identifier(); got != want { + t.Fatalf("unexpected account at step %d: got %q want %q", i+1, got, want) + } + pool.Release(acc.Identifier()) + } +} + func TestPoolAcquireWaitQueuesAndSucceedsAfterRelease(t *testing.T) { pool := newSingleAccountPoolForTest(t, "1") first, ok := pool.Acquire("", nil)