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
path: root/spec
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-12-01 16:52:16 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2017-12-06 17:59:37 +0300
commit856447ccd305832c4e9421ab9e81d63eea348203 (patch)
tree99df49e2050a3dcb2f2d289a8a728fa5b28f83be /spec
parent483b5f1bfac5e338fab0e11f2045254f70df8fc1 (diff)
Throttle the number of UPDATEs triggered by touch
This throttles the number of UPDATE queries that can be triggered by calling "touch" on a Note, Issue, or MergeRequest. For Note objects we also take care of updating the associated "noteable" relation in a smarter way than Rails does by default.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/concerns/issuable_spec.rb2
-rw-r--r--spec/models/issue_spec.rb4
-rw-r--r--spec/models/merge_request_spec.rb4
-rw-r--r--spec/models/note_spec.rb2
-rw-r--r--spec/support/shared_examples/throttled_touch.rb20
5 files changed, 30 insertions, 2 deletions
diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb
index a53b59c4e08..9df26f06a11 100644
--- a/spec/models/concerns/issuable_spec.rb
+++ b/spec/models/concerns/issuable_spec.rb
@@ -171,7 +171,7 @@ describe Issuable do
it "returns false when record has been updated" do
allow(issue).to receive(:today?).and_return(true)
- issue.touch
+ issue.update_attribute(:updated_at, 1.hour.ago)
expect(issue.new?).to be_falsey
end
end
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index 5f901262598..0ea287d007a 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -765,4 +765,8 @@ describe Issue do
expect(described_class.public_only).to eq([public_issue])
end
end
+
+ it_behaves_like 'throttled touch' do
+ subject { create(:issue, updated_at: 1.hour.ago) }
+ end
end
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index e606fb027b5..71fbb82184c 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -1851,4 +1851,8 @@ describe MergeRequest do
.to change { project.open_merge_requests_count }.from(1).to(0)
end
end
+
+ it_behaves_like 'throttled touch' do
+ subject { create(:merge_request, updated_at: 1.hour.ago) }
+ end
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 6e7e8c4c570..e1a0c55b6a6 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -5,7 +5,7 @@ describe Note do
describe 'associations' do
it { is_expected.to belong_to(:project) }
- it { is_expected.to belong_to(:noteable).touch(true) }
+ it { is_expected.to belong_to(:noteable).touch(false) }
it { is_expected.to belong_to(:author).class_name('User') }
it { is_expected.to have_many(:todos).dependent(:destroy) }
diff --git a/spec/support/shared_examples/throttled_touch.rb b/spec/support/shared_examples/throttled_touch.rb
new file mode 100644
index 00000000000..4a25bb9b750
--- /dev/null
+++ b/spec/support/shared_examples/throttled_touch.rb
@@ -0,0 +1,20 @@
+shared_examples_for 'throttled touch' do
+ describe '#touch' do
+ it 'updates the updated_at timestamp' do
+ Timecop.freeze do
+ subject.touch
+ expect(subject.updated_at).to eq(Time.zone.now)
+ end
+ end
+
+ it 'updates the object at most once per minute' do
+ first_updated_at = Time.zone.now - (ThrottledTouch::TOUCH_INTERVAL * 2)
+ second_updated_at = Time.zone.now - (ThrottledTouch::TOUCH_INTERVAL * 1.5)
+
+ Timecop.freeze(first_updated_at) { subject.touch }
+ Timecop.freeze(second_updated_at) { subject.touch }
+
+ expect(subject.updated_at).to eq(first_updated_at)
+ end
+ end
+end