2026-03-06 04:27:41 +08:00
|
|
|
//go:build unit
|
|
|
|
|
|
2026-03-06 05:07:10 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-06 04:27:41 +08:00
|
|
|
func intPtrHelper(v int) *int { return &v }
|
|
|
|
|
|
2026-03-06 05:07:10 +08:00
|
|
|
func TestEffectiveLoadFactor_NilAccount(t *testing.T) {
|
|
|
|
|
var a *Account
|
|
|
|
|
require.Equal(t, 1, a.EffectiveLoadFactor())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEffectiveLoadFactor_NilLoadFactor_PositiveConcurrency(t *testing.T) {
|
|
|
|
|
a := &Account{Concurrency: 5}
|
|
|
|
|
require.Equal(t, 5, a.EffectiveLoadFactor())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEffectiveLoadFactor_NilLoadFactor_ZeroConcurrency(t *testing.T) {
|
|
|
|
|
a := &Account{Concurrency: 0}
|
|
|
|
|
require.Equal(t, 1, a.EffectiveLoadFactor())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEffectiveLoadFactor_PositiveLoadFactor(t *testing.T) {
|
2026-03-06 04:27:41 +08:00
|
|
|
a := &Account{Concurrency: 5, LoadFactor: intPtrHelper(20)}
|
2026-03-06 05:07:10 +08:00
|
|
|
require.Equal(t, 20, a.EffectiveLoadFactor())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEffectiveLoadFactor_ZeroLoadFactor_FallbackToConcurrency(t *testing.T) {
|
2026-03-06 04:27:41 +08:00
|
|
|
a := &Account{Concurrency: 5, LoadFactor: intPtrHelper(0)}
|
2026-03-06 05:07:10 +08:00
|
|
|
require.Equal(t, 5, a.EffectiveLoadFactor())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEffectiveLoadFactor_NegativeLoadFactor_FallbackToConcurrency(t *testing.T) {
|
2026-03-06 04:27:41 +08:00
|
|
|
a := &Account{Concurrency: 3, LoadFactor: intPtrHelper(-1)}
|
2026-03-06 05:07:10 +08:00
|
|
|
require.Equal(t, 3, a.EffectiveLoadFactor())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEffectiveLoadFactor_ZeroLoadFactor_ZeroConcurrency(t *testing.T) {
|
2026-03-06 04:27:41 +08:00
|
|
|
a := &Account{Concurrency: 0, LoadFactor: intPtrHelper(0)}
|
2026-03-06 05:07:10 +08:00
|
|
|
require.Equal(t, 1, a.EffectiveLoadFactor())
|
|
|
|
|
}
|