fflush (stdout);
        }
 
+       status = notmuch_database_begin_atomic (notmuch);
+       if (status) {
+           ret = status;
+           goto DONE;
+       }
+
        status = notmuch_database_add_message (notmuch, next, &message);
        switch (status) {
        /* success */
            goto DONE;
        }
 
+       status = notmuch_database_end_atomic (notmuch);
+       if (status) {
+           ret = status;
+           goto DONE;
+       }
+
        if (message) {
            notmuch_message_destroy (message);
            message = NULL;
 {
     notmuch_status_t status;
     notmuch_message_t *message;
+    status = notmuch_database_begin_atomic (notmuch);
+    if (status)
+       return status;
     message = notmuch_database_find_message_by_filename (notmuch, path);
     status = notmuch_database_remove_message (notmuch, path);
     if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
     } else
        add_files_state->removed_messages++;
     notmuch_message_destroy (message);
+    notmuch_database_end_atomic (notmuch);
     return status;
 }
 
 
 done
 
 test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
-test_subtest_known_broken
 test_expect_equal_file GDB searchall expectall
 
 test_expect_success GDB "detected $outcount>10 abort points" "test $outcount -gt 10"