Skip to content

Commit 79c093f

Browse files
authored
Use TestOnly property in example tests (#440)
I was looking into what was making the example tests so slow (some like the periodic job enqueuer one often take 3 seconds to run), and it turns out that the lion's share of it is from from service start up jitter. Example tests aren't in the main `river` package (they're in `river_test`) so they didn't previously have a way of interacting with the client in such a way as to disable stagger. Luckily, we do have a way now. Take advantage of the recently introduced `TestOnly` client property from #414 to make all the examples faster.
1 parent d759137 commit 79c093f

16 files changed

Lines changed: 32 additions & 16 deletions

example_batch_insert_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func Example_batchInsert() {
5252
Queues: map[string]river.QueueConfig{
5353
river.QueueDefault: {MaxWorkers: 100},
5454
},
55-
Workers: workers,
55+
TestOnly: true, // suitable only for use in tests; remove for live environments
56+
Workers: workers,
5657
})
5758
if err != nil {
5859
panic(err)

example_complete_job_within_tx_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ func Example_completeJobWithinTx() {
7878
Queues: map[string]river.QueueConfig{
7979
river.QueueDefault: {MaxWorkers: 100},
8080
},
81-
Workers: workers,
81+
TestOnly: true, // suitable only for use in tests; remove for live environments
82+
Workers: workers,
8283
})
8384
if err != nil {
8485
panic(err)

example_cron_job_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func Example_cronJob() {
6868
Queues: map[string]river.QueueConfig{
6969
river.QueueDefault: {MaxWorkers: 100},
7070
},
71-
Workers: workers,
71+
TestOnly: true, // suitable only for use in tests; remove for live environments
72+
Workers: workers,
7273
})
7374
if err != nil {
7475
panic(err)

example_custom_insert_opts_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ func Example_customInsertOpts() {
7777
river.QueueDefault: {MaxWorkers: 100},
7878
"high_priority": {MaxWorkers: 100},
7979
},
80-
Workers: workers,
80+
TestOnly: true, // suitable only for use in tests; remove for live environments
81+
Workers: workers,
8182
})
8283
if err != nil {
8384
panic(err)

example_error_handler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ func Example_errorHandler() {
8181
Queues: map[string]river.QueueConfig{
8282
river.QueueDefault: {MaxWorkers: 10},
8383
},
84-
Workers: workers,
84+
TestOnly: true, // suitable only for use in tests; remove for live environments
85+
Workers: workers,
8586
})
8687
if err != nil {
8788
panic(err)

example_graceful_shutdown_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func Example_gracefulShutdown() {
7272
Queues: map[string]river.QueueConfig{
7373
river.QueueDefault: {MaxWorkers: 100},
7474
},
75-
Workers: workers,
75+
TestOnly: true, // suitable only for use in tests; remove for live environments
76+
Workers: workers,
7677
})
7778
if err != nil {
7879
panic(err)

example_insert_and_work_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func Example_insertAndWork() {
5555
Queues: map[string]river.QueueConfig{
5656
river.QueueDefault: {MaxWorkers: 100},
5757
},
58-
Workers: workers,
58+
TestOnly: true, // suitable only for use in tests; remove for live environments
59+
Workers: workers,
5960
})
6061
if err != nil {
6162
panic(err)

example_job_cancel_from_client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func Example_jobCancelFromClient() {
5959
Queues: map[string]river.QueueConfig{
6060
river.QueueDefault: {MaxWorkers: 10},
6161
},
62-
Workers: workers,
62+
TestOnly: true, // suitable only for use in tests; remove for live environments
63+
Workers: workers,
6364
})
6465
if err != nil {
6566
panic(err)

example_job_cancel_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ func Example_jobCancel() { //nolint:dupl
5656
Queues: map[string]river.QueueConfig{
5757
river.QueueDefault: {MaxWorkers: 10},
5858
},
59-
Workers: workers,
59+
TestOnly: true, // suitable only for use in tests; remove for live environments
60+
Workers: workers,
6061
})
6162
if err != nil {
6263
panic(err)

example_job_snooze_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func Example_jobSnooze() { //nolint:dupl
5858
Queues: map[string]river.QueueConfig{
5959
river.QueueDefault: {MaxWorkers: 10},
6060
},
61-
Workers: workers,
61+
TestOnly: true, // suitable only for use in tests; remove for live environments
62+
Workers: workers,
6263
})
6364
if err != nil {
6465
panic(err)

0 commit comments

Comments
 (0)