Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/workers/idempotency_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/workers/idempotency_shared_examples.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/support/shared_examples/workers/idempotency_shared_examples.rb b/spec/support/shared_examples/workers/idempotency_shared_examples.rb
new file mode 100644
index 00000000000..19be1fe2c9d
--- /dev/null
+++ b/spec/support/shared_examples/workers/idempotency_shared_examples.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+# This shared_example requires the following variables:
+# - job_args (if not given, will fallback to call perform without arguments)
+#
+# Usage:
+#
+# include_examples 'an idempotent worker' do
+# it 'checks the side-effects for multiple calls' do
+# # it'll call the job's perform method 3 times
+# # by default.
+# subject
+#
+# expect(model.state).to eq('state')
+# end
+# end
+#
+RSpec.shared_examples 'an idempotent worker' do
+ # Avoid stubbing calls for a more accurate run.
+ subject do
+ defined?(job_args) ? perform_multiple(job_args) : perform_multiple
+ end
+
+ it 'is labeled as idempotent' do
+ expect(described_class).to be_idempotent
+ end
+
+ it 'performs multiple times sequentially without raising an exception' do
+ expect { subject }.not_to raise_error
+ end
+end