MCPcopy Create free account
hub / github.com/riverqueue/river / TestUniqueOpts

Function TestUniqueOpts

client_test.go:9228–9339  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9226}
9227
9228func TestUniqueOpts(t *testing.T) {
9229 t.Parallel()
9230
9231 ctx := context.Background()
9232
9233 type testBundle struct{}
9234
9235 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
9236 t.Helper()
9237
9238 workers := NewWorkers()
9239 AddWorker(workers, &noOpWorker{})
9240
9241 var (
9242 dbPool = riversharedtest.DBPool(ctx, t)
9243 driver = riverpgxv5.New(dbPool)
9244 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
9245 config = newTestConfig(t, schema)
9246 client = newTestClient(t, dbPool, config)
9247 )
9248
9249 // Tests that use ByPeriod below can be sensitive to intermittency if
9250 // the tests run at say 23:59:59.998, then it's possible to accidentally
9251 // cross a period threshold, even if very unlikely. So here, seed mostly
9252 // the current time, but make sure it's nicened up a little to be
9253 // roughly in the middle of the hour and well clear of any period
9254 // boundaries.
9255 client.baseService.Time.StubNow(
9256 time.Now().Truncate(1 * time.Hour).Add(37*time.Minute + 23*time.Second + 123*time.Millisecond).UTC(),
9257 )
9258
9259 return client, &testBundle{}
9260 }
9261
9262 t.Run("DeduplicatesJobs", func(t *testing.T) {
9263 t.Parallel()
9264
9265 client, _ := setup(t)
9266
9267 uniqueOpts := UniqueOpts{
9268 ByPeriod: 24 * time.Hour,
9269 }
9270
9271 insertRes0, err := client.Insert(ctx, noOpArgs{}, &InsertOpts{
9272 UniqueOpts: uniqueOpts,
9273 })
9274 require.NoError(t, err)
9275 require.False(t, insertRes0.UniqueSkippedAsDuplicate)
9276
9277 insertRes1, err := client.Insert(ctx, noOpArgs{}, &InsertOpts{
9278 UniqueOpts: uniqueOpts,
9279 })
9280 require.NoError(t, err)
9281 require.True(t, insertRes1.UniqueSkippedAsDuplicate)
9282
9283 // Expect the same job to come back.
9284 require.Equal(t, insertRes0.Job.ID, insertRes1.Job.ID)
9285 })

Callers

nothing calls this directly

Calls 14

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
JobStatesFunction · 0.92
NewWorkersFunction · 0.85
AddWorkerFunction · 0.85
newTestClientFunction · 0.85
InsertMethod · 0.80
newTestConfigFunction · 0.70
HelperMethod · 0.65
StubNowMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…