From 28c48804be86c1fbd0bbc16f33cbe4912ca65cce Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 6 Feb 2019 22:21:24 -0800 Subject: Fix failing test in spec/workers/post_receive_spec.rb 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 --- spec/workers/post_receive_spec.rb | 15 +++++++++++---- 1 file 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 -- cgit v1.2.1