Skip to content

Conversation

@jestradaMS
Copy link
Contributor

@jestradaMS jestradaMS commented Nov 15, 2025

Description

This pull request introduces several improvements and fixes to the FHIR reindexing operation, as well as enhancements to end-to-end (E2E) testing infrastructure. The main changes include more accurate resource counting during reindexing, configuration overrides for faster E2E reindex tests, and improved logging and error handling. Additionally, new E2E test files and documentation for reindexing have been added.

Reindexing logic and correctness improvements:

  • Improved resource counting in ReindexOrchestratorJob: After calculating initial resource ranges, the code now double-checks and corrects counts for each resource type, ensuring that zero-count resource types are accurately reflected and subtracted from the total job count. This prevents unnecessary processing of empty resource ranges.
  • The logic for determining whether there is any work left in a reindex job has been fixed to check for positive resource counts, preventing jobs from proceeding unnecessarily.
  • The filtering of search parameters for reindexing now directly selects URIs with valid statuses, simplifying and correcting the logic to avoid issues with case-variant duplicates.

Testing infrastructure and configuration:

  • Added a new ReindexTestFixture class for E2E tests, which overrides configuration to minimize reindex delays and polling intervals, and ensures test data is cleaned up before and after tests. This results in faster and more reliable E2E reindex tests.
  • Included new E2E test files for reindexing (ReindexTestFixture.cs, ReindexTests.cs) and related documentation (README.md) in the project items. [1] [2]

Logging and error handling:

  • Improved logging in ReindexProcessingJob by using structured logging with named parameters, making logs easier to parse and analyze.
  • Fixed error handling to ensure the failed resource count is correctly set from the job definition, not from a possibly stale variable, in both FHIR and general exception cases.

Related issues

Addresses AB#178077, AB#175213, AB#178083

Testing

Describe how this change was tested.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

Simplified the search parameter status filtering in ReindexOrchestratorJob by removing unnecessary dictionary creation. The new implementation directly filters the collection to get valid URIs, which is more straightforward and handles case-variant duplicates naturally.

Changes:
- Removed intermediate dictionary for O(1) lookups by URI
- Changed to direct LINQ filtering on the status collection
- Removed case-insensitive string comparer (now uses default equality)
- Updated comment to clarify handling of case-variant duplicates
- Added comprehensive unit tests for the reindex orchestrator job
- Removed unused MediatR import and added System.Threading.Tasks from ReindexOrchestratorJobTests

This refactoring maintains the same functional behavior while improving code readability and includes better test coverage.
**Changes:**
- Modified GetReindexRequestHandler to check for active reindex jobs before listing all jobs
- Added GetActiveReindexJob method to retrieve single active job when available
- Enhanced ReindexOrchestratorJob to verify resource counts without ignoring hash values
- Fixed logic error in CheckJobRecordForAnyWork (changed <= to > for count comparison)
- Added zero-count resource detection and JobRecordCount adjustment to prevent processing empty ranges
- Adding E2E tests for Reindex
- Fixing SortTests
@jestradaMS jestradaMS requested a review from a team as a code owner November 15, 2025 00:07
@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

- Add check for cancelled jobs when determining failure status
- Prevent incorrect status updates when in-flight jobs exist during race conditions
- Only create reindex processing jobs if none exist to avoid duplicates
- Add early cancellation checks before creating and enqueueing jobs
- Ensure status remains Running if in-flight jobs exist
- Added loop to handle continuation tokens when working with resources from Cosmos
- Added missing filter to QueryBuilder for Cosmos DB to filter is history as well as is deleted
- Added check to CosmosQueueClient to prevent race condition of submitting new jobs when cancellation was requested
- Added MaxRunningTaskCount = 4 to Reindex Operation
…ndex tests

- Reduce SearchParameterCacheRefreshIntervalSeconds from 5 to 2 seconds
- Reduce JobHosting PollingFrequencyInSeconds from 5 to 2 seconds
- Add Person resource cleanup in test fixture initialization
- Add comprehensive test for mixed zero and non-zero count resources
- Include Person resources (2000) alongside Specimen resources (5000) in test data
- Create separate search parameters for different resource types
- Verify search parameter status updates only after all reindex jobs complete

These changes improve test execution speed and ensure proper cleanup of Person resources between test runs while adding coverage for multi-resource reindexing scenarios.
enhancement(ci): added seperate e2e tests task for IndexAndReindex categories

Adding in new template (e2e-test-reindex.yml) for handling IndexAndReindex test execution in parallel to other tests to not add additional time to verall e2e tests.

Extract the Azure PowerShell variable setup logic from e2e-tests.yml into a separate reusable template (e2e-set-variables.yml). This improves maintainability by centralizing the Key Vault secret retrieval, storage account configuration, and environment variable setup logic that can be shared across multiple pipeline jobs.
- Add retry to Verify to account for race conditions
- Added specimen.subject
- Removed unncessary check in orchestrator
- updated run-test.yml job ordering
…n ReindexProcessingJob to ensure that should any race conditions occur where a job is dequeued before next background sync runs it does not fail the jobs.
testing change to prevent status from impacting hashmap.
changing opperand on staus check to !=
@jestradaMS jestradaMS added Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Schema Version unchanged Build labels Dec 4, 2025
@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jestradaMS
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. Build Enhancement-Test Enhancement on tests. Schema Version unchanged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants