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
This commit is contained in:
Stan Hu 2019-02-06 22:21:24 -08:00
parent 3daa53e821
commit 28c48804be
1 changed files with 11 additions and 4 deletions

View File

@ -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