Skip to content

TestGnsiAuthzRotation subtests are flaky due to race between server-side revert and test reset #624

Description

@sigabrtv1-ui

Summary

TestGnsiAuthzRotation intermittently fails in the ADO PR pipeline. Four subtests within the parent function are affected: RotatePolicyEmptyRequest, RotatePolicyEmptyUploadRequest, RotatePolicyWrongJSON, and RotatePolicyNoVersion. All other subtests in TestGnsiAuthzRotation are unaffected.

Symptom

The four subtests call expectPolicyMatch(t, authzTestPolicyFile, authzTestPolicyFileV1) to verify the policy file still contains V1 content after a failed rotation attempt. The assertion fails because the file contains stale or unexpected content.

Root Cause Analysis

The RotateStreamSendError subtest (which runs immediately before the failing tests) triggers a race condition:

  1. The test sends a valid V2 policy to the server, then immediately closes the gRPC connection.
  2. The server-side Rotate handler processes the upload and writes V2 to disk via saveToAuthzFile.
  3. When the server attempts stream.Send(resp), it fails due to the closed connection.
  4. The server enters the error path and calls copyFile(backup, policyFile) to revert — but this runs asynchronously in the server's goroutine.
  5. Meanwhile, back in the test loop, resetAuthzPolicyFile writes V1 to the policy file.

Steps 4 and 5 race: the server-side revert can overwrite the test's V1 reset with the checkpoint backup content, leaving the file in a state that does not match authzTestPolicyFileV1. The four subsequent subtests then fail their expectPolicyMatch assertions.

Affected Tests

  • File: gnmi_server/gnsi_authz_test.go
  • Parent: TestGnsiAuthzRotation
  • Subtests:
    • RotatePolicyEmptyRequest (line 190)
    • RotatePolicyEmptyUploadRequest (line 218)
    • RotatePolicyWrongJSON (line 250)
    • RotatePolicyNoVersion (line 281)
  • Other subtests in TestGnsiAuthzRotation are not affected

Temporary Mitigation

The affected subtests will be temporarily skipped via t.Skip() with a reference to this issue.

Proposed Fix

Either:

  • Add synchronization in RotateStreamSendError to wait for the server-side Rotate handler to fully return before the test loop calls resetAuthzPolicyFile (e.g., poll the authz mutex or add a completion callback).
  • Or reorder the test cases so RotateStreamSendError runs after the error-path subtests that depend on V1 file content.

References

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions