Skip to content

Stabilize async Lucene index test by removing shared temp-root deletion#444

Merged
Shazwazza merged 2 commits into
support/3.xfrom
copilot/fix-github-actions-build-job
May 27, 2026
Merged

Stabilize async Lucene index test by removing shared temp-root deletion#444
Shazwazza merged 2 commits into
support/3.xfrom
copilot/fix-github-actions-build-job

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor

The build GitHub Actions job was failing due to an intermittent test race in LuceneIndexTests. A filesystem-backed async index test could delete a shared temp root while another run was still writing Lucene segment files, causing DirectoryNotFoundException.

  • Problem scope

    • Failure surfaced in Index_Read_And_Write_Ensure_No_Errors_In_Async(..., inMemory: false) when using FSDirectory under /tmp/ExamineTests.
  • Code change

    • Removed deletion of the shared temp base path (/tmp/ExamineTests) from test setup.
    • Kept per-test isolation by creating a GUID-scoped subdirectory under the shared base.
    • Existing per-test cleanup of that GUID directory remains in place.
  • Why this resolves the failure

    • Eliminates cross-test/process interference from recursive base-directory deletion while preserving isolated temp storage for each run.
var tempBasePath = Path.Combine(Path.GetTempPath(), "ExamineTests");
Directory.CreateDirectory(tempBasePath);

var tempPath = Path.Combine(tempBasePath, Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);

temp = new DirectoryInfo(tempPath);
directory = FSDirectory.Open(temp);

Copilot AI changed the title [WIP] Fix failing GitHub Actions job build Stabilize async Lucene index test by removing shared temp-root deletion May 27, 2026
Copilot AI requested a review from Shazwazza May 27, 2026 16:29
@Shazwazza Shazwazza marked this pull request as ready for review May 27, 2026 21:39
@greptile-apps

greptile-apps Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes an intermittent DirectoryNotFoundException in the async Lucene index test by removing the shared base-directory deletion from test setup. Previously, each test would recursively delete /tmp/ExamineTests before creating its own GUID subdirectory, which caused a race when two test runs overlapped on the filesystem. The fix replaces that deletion with Directory.CreateDirectory, which is idempotent and safe to call concurrently.

  • Removed the Directory.Delete(tempBasePath, true) block in the inMemory: false branch of Index_Read_And_Write_Ensure_No_Errors_In_Async, leaving per-test GUID scoping and per-test cleanup untouched.
  • The base path (/tmp/ExamineTests) now persists across test runs; individual GUID subdirectories are still deleted in the finally block as before.

Confidence Score: 5/5

Safe to merge — the change is a minimal, targeted removal of a shared-path deletion that was the root cause of the reported race condition.

The only code removed is the recursive deletion of the shared base directory; per-test GUID scoping and per-test cleanup in the finally block are untouched. Directory.CreateDirectory is idempotent and safe to call from concurrent test runners, so the fix directly addresses the race. No production code is affected.

No files require special attention.

Important Files Changed

Filename Overview
src/Examine.Test/Examine.Lucene/Index/LuceneIndexTests.cs Removes recursive deletion of the shared temp base path from test setup, replacing it with an idempotent CreateDirectory call; per-test GUID subdirectory isolation and cleanup are preserved.

Sequence Diagram

sequenceDiagram
    participant T1 as Test Run 1 (inMemory:false)
    participant T2 as Test Run 2 (inMemory:false)
    participant FS as Filesystem (/tmp/ExamineTests)

    Note over T1,T2: BEFORE (race condition)
    T1->>FS: Directory.Delete(tempBasePath, true)
    T2->>FS: Directory.Delete(tempBasePath, true)
    T1->>FS: CreateDirectory(GUID-1)
    T2->>FS: CreateDirectory(GUID-2)
    T1->>FS: FSDirectory.Open(GUID-1) — may fail if T2 deleted base

    Note over T1,T2: AFTER (race resolved)
    T1->>FS: Directory.CreateDirectory(tempBasePath)
    T2->>FS: Directory.CreateDirectory(tempBasePath)
    T1->>FS: CreateDirectory(GUID-1)
    T2->>FS: CreateDirectory(GUID-2)
    T1->>FS: FSDirectory.Open(GUID-1) — safe, base always exists
    T2->>FS: FSDirectory.Open(GUID-2) — safe, base always exists
    T1->>FS: finally: temp.Delete(GUID-1, true)
    T2->>FS: finally: temp.Delete(GUID-2, true)
Loading

Reviews (1): Last reviewed commit: "test: avoid deleting shared temp root in..." | Re-trigger Greptile

@Shazwazza Shazwazza merged commit 74b4fe7 into support/3.x May 27, 2026
15 checks passed
@Shazwazza Shazwazza deleted the copilot/fix-github-actions-build-job branch May 27, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants