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

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.

diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rb
index ac256d2..a1be88f 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)

GitHub sha: b579e9a7de8724938361e44ae486047084d679ad

This commit appears in #13601 which was approved by tgxworld. It was merged by martin.