DEV: Try fix flaky topic view serializer spec (#13601)

This is just a hunch, but this is quite a complex test.
I think that there is some timing issue where the jobs
enqueued for generating the thumbnails via the serializer
thumbnails method and they aren't generated in time before
we do the json[:thumbnails] check. Split the tests up
into two, with one checking the right jobs are enqueued
and another with Jobs.run_immediately! that checks that
json[:thumbnails] is correct.
This commit is contained in:
Martin Brennan 2021-07-01 12:52:40 +10:00 committed by GitHub
parent 3312e09d02
commit b579e9a7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -57,7 +57,7 @@ describe TopicViewSerializer do
expect(json[:image_url]).to end_with(image_upload.url) expect(json[:image_url]).to end_with(image_upload.url)
end end
it 'should have thumbnails' do it 'should have thumbnail jobs enqueued' do
SiteSetting.create_thumbnails = true SiteSetting.create_thumbnails = true
Discourse.redis.del(topic.thumbnail_job_redis_key(Topic.thumbnail_sizes)) Discourse.redis.del(topic.thumbnail_job_redis_key(Topic.thumbnail_sizes))
@ -72,6 +72,16 @@ describe TopicViewSerializer do
expect do expect do
json = serialize_topic(topic, user) json = serialize_topic(topic, user)
end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(0) end.to change { Jobs::GenerateTopicThumbnails.jobs.size }.by(0)
end
it 'should have thumbnails after jobs run' do
Jobs.run_immediately!
SiteSetting.create_thumbnails = true
Discourse.redis.del(topic.thumbnail_job_redis_key(Topic.thumbnail_sizes))
json = serialize_topic(topic, user)
topic.generate_thumbnails!
json = serialize_topic(topic, user)
# Original + Optimized # Original + Optimized
expect(json[:thumbnails].length).to eq(2) expect(json[:thumbnails].length).to eq(2)