From b579e9a7de8724938361e44ae486047084d679ad Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 1 Jul 2021 12:52:40 +1000 Subject: [PATCH] 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. --- spec/serializers/topic_view_serializer_spec.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rb index ac256d27928..a1be88f7800 100644 --- a/spec/serializers/topic_view_serializer_spec.rb +++ b/spec/serializers/topic_view_serializer_spec.rb @@ -57,7 +57,7 @@ describe TopicViewSerializer do expect(json[:image_url]).to end_with(image_upload.url) end - it 'should have thumbnails' do + it 'should have thumbnail jobs enqueued' do SiteSetting.create_thumbnails = true Discourse.redis.del(topic.thumbnail_job_redis_key(Topic.thumbnail_sizes)) @@ -72,6 +72,16 @@ describe TopicViewSerializer do expect do json = serialize_topic(topic, user) 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 expect(json[:thumbnails].length).to eq(2)