summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-02-06 22:21:24 -0800
committerStan Hu <stanhu@gmail.com>2019-02-06 22:30:58 -0800
commit28c48804be86c1fbd0bbc16f33cbe4912ca65cce (patch)
treeaa252e1da74c462996645135edd6b63608504140
parent3daa53e821c68069d68627bebd58a8291269106d (diff)
downloadgitlab-ce-sh-fix-ee-issue-8871.tar.gz
Fix failing test in spec/workers/post_receive_spec.rbsh-fix-ee-issue-8871
This is what was happening before: 1. `Project#set_timestamps_for_create` was called at creation time and set the `last_activity_at` and `last_repository_updated_at` to the current timestamp T. 2. The test ran `PostReceive#perform`, which then called `PostReceive#process_wiki_changes`. If less than 500 milliseconds elapsed since T, then the update would just set the timestamp to T. To fix this problem, we can just use Timecop to ensure at least one second has elapsed after attempting to process changes. Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/8871
-rw-r--r--spec/workers/post_receive_spec.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index 9176eb12b12..caae46a3175 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -141,11 +141,18 @@ describe PostReceive do
let(:gl_repository) { "wiki-#{project.id}" }
it 'updates project activity' do
- described_class.new.perform(gl_repository, key_id, base64_changes)
+ # Force Project#set_timestamps_for_create to initialize timestamps
+ project
- expect { project.reload }
- .to change(project, :last_activity_at)
- .and change(project, :last_repository_updated_at)
+ # MySQL drops milliseconds in the timestamps, so advance at least
+ # a second to ensure we see changes.
+ Timecop.freeze(1.second.from_now) do
+ expect do
+ described_class.new.perform(gl_repository, key_id, base64_changes)
+ project.reload
+ end.to change(project, :last_activity_at)
+ .and change(project, :last_repository_updated_at)
+ end
end
end