Add a channel concurrency wait plan so saturated account/channel selection can distinguish no-wait, queue-full, and wait-for-slot outcomes while preserving fallback to other available channels first.
27 lines
564 B
Go
27 lines
564 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTryEnterChannelConcurrencyWaitQueueRejectsWhenPlanDisabled(t *testing.T) {
|
|
canWait, release := TryEnterChannelConcurrencyWaitQueue(1, 0)
|
|
|
|
require.False(t, canWait)
|
|
require.NotNil(t, release)
|
|
release()
|
|
}
|
|
|
|
func TestWaitForChannelConcurrencySlotTimesOut(t *testing.T) {
|
|
ctx := context.Background()
|
|
acquired, release, err := WaitForChannelConcurrencySlot(ctx, 1, 1, 0)
|
|
|
|
require.False(t, acquired)
|
|
require.NotNil(t, release)
|
|
require.Error(t, err)
|
|
release()
|
|
}
|