(t *testing.T)
| 208 | } |
| 209 | |
| 210 | func TestReleaseSequenceWait(t *testing.T) { |
| 211 | ctx := base.TestCtx(t) |
| 212 | bucket := base.GetTestBucket(t) |
| 213 | defer bucket.Close(ctx) |
| 214 | |
| 215 | sgw, err := base.NewSyncGatewayStats() |
| 216 | require.NoError(t, err) |
| 217 | dbstats, err := sgw.NewDBStats("", false, false, false, nil, nil) |
| 218 | require.NoError(t, err) |
| 219 | testStats := dbstats.Database() |
| 220 | a, err := newSequenceAllocator(ctx, bucket.GetSingleDataStore(), testStats, base.DefaultMetadataKeys) |
| 221 | require.NoError(t, err) |
| 222 | defer a.Stop(ctx) |
| 223 | |
| 224 | startTime := time.Now().Add(-1 * time.Second) |
| 225 | amountWaited := a.waitForReleasedSequences(ctx, startTime) |
| 226 | // Time will be a little less than a.releaseSequenceWait - 1*time.Second - validate |
| 227 | // there's a non-zero wait that's less than releaseSequenceWait |
| 228 | assert.True(t, amountWaited > 0) |
| 229 | assert.True(t, amountWaited < a.releaseSequenceWait) |
| 230 | |
| 231 | // Validate no wait for a time in the past longer than releaseSequenceWait |
| 232 | noWaitTime := time.Now().Add(-5 * time.Second) |
| 233 | amountWaited = a.waitForReleasedSequences(ctx, noWaitTime) |
| 234 | assert.Equal(t, time.Duration(0), amountWaited) |
| 235 | } |
| 236 | |
| 237 | func assertNewAllocatorStats(t *testing.T, stats *base.DatabaseStats, incrCount, reservedCount, assignedCount, releasedCount int64, lastAssignedValue, lastReservedValue uint64) { |
| 238 | assert.Equal(t, incrCount, stats.SequenceIncrCount.Value()) |
nothing calls this directly
no test coverage detected