Commit 28c48804 authored by Stan Hu's avatar Stan Hu

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
parent 3daa53e8
......@@ -141,13 +141,20 @@ 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)
# 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
context "webhook" do
it "fetches the correct project" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment