Skip to content

Fix flaky spec in reindexing_spec.rb

Simon Tomlinson requested to merge stomlinson/fix-master-broken-5020 into master

What does this MR do and why?

Fix flaky spec in reindexing_spec.rb

The spec spec/lib/gitlab/database/reindexing_spec.rb:270 'drops both leftover indexes' was depending on the leftover indexes from PostgresIndex.reindexing_leftovers being returned in a consistent order despite a missing order by clause.

Very rarely these indexes would be returned by the query in the opposite order, leading to a spec failure.

Order the indexes returned from this scope by name so that the ordering is consistent.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

I could only get postgres to return results in the wrong order when running with a single database and multiple connections for main and ci.

I was able to reproduce the failure locally by running the entire spec file in a loop using bash roughly 20 times.

To reproduce (without this MR): for i in $(seq 50); do bundle exec rspec spec/lib/gitlab/database/reindexing_spec.rb || break; done

Usually this fails for me around iteration 20, I have a suspicion that the postgres catalog runs a vacuum around the 50th inserted index and that causes the failure (and we create 2 indexes per test run).

To verify that this fixes the problem, run the above snippet with this MR and see that the test never fails.

Merge request reports