sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 6a5717ce15cb23dbe7ddfe3db74b6f63d22034db
parent 2837f0614381052c77e213cf6ab23729ba84777b
Author: Dan Callaghan <djc@djc.id.au>
Date:   Mon,  6 Apr 2026 12:37:45 +1000

tests: avoid leaking index writes from TestIndex

Fixes a randomly occurring test failure:

    Finished in 5.187590s, 16.9636 runs/s, 74.4083 assertions/s.

      1) Failure:
    TestSupSyncBackMaildir#test_it_syncs_seen_unread_flags [/home/runner/work/sup/sup/test/integration/test_sup-sync-back-maildir.rb:36]:
    Expected true to not be truthy.

    88 runs, 386 assertions, 1 failures, 0 errors, 0 skips

Reproducible using:

    nix-shell contrib/nix/ruby2.6-shell.nix --run 'rake test TESTOPTS=--seed=29609'

Bisected to commit b49dcfe7dd25100feb88ed8aefe629fd91423a26.

It seems Dir.mktmpdir is aggressively reusing temp directory names(!)
which in itself would be fine, since each test cleans up its temp
directory in teardown. But it seems that the newly added TestIndex was
leaving the Xapian database open and Xapian may write to it even after
the test teardown has finished... apparently re-creating the cleaned-up
temp directory in the process(!).

Since we have no way to explicitly close or destroy the index, the best
we can do is to explicitly flush it before removing the temp directory
so that it will not try to write again later.

Diffstat:
M test/unit/test_index.rb | 2 ++
1 file changed, 2 insertions(+), 0 deletions(-)
diff --git a/test/unit/test_index.rb b/test/unit/test_index.rb
@@ -7,11 +7,13 @@ class TestIndex < Minitest::Test
   def setup
     @path = Dir.mktmpdir
     Redwood::start
+    Redwood::Logger.remove_sink $stderr
     Redwood::Index.init @path
     Redwood::Index.load
   end
 
   def teardown
+    Redwood::Index.save_index
     ObjectSpace.each_object(Class).select {|a| a < Redwood::Singleton}.each do |klass|
       klass.deinstantiate! unless klass == Redwood::Logger
     end