Skip to content

Conversation

@rjrudin
Copy link
Contributor

@rjrudin rjrudin commented Jul 23, 2025

The "clear" that happens via DELETE v1/search causes intermittent failures on Jenkins.

Copilot AI review requested due to automatic review settings July 23, 2025 14:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the database clearing mechanism in test infrastructure to address intermittent failures on Jenkins. The change replaces the REST API-based deletion approach with an XQuery-based solution to improve reliability.

  • Replaces DELETE v1/search REST API call with XQuery evaluation for database clearing
  • Adds logging to track the number of URIs deleted during the clear operation
  • Introduces slf4j import for logging functionality

Comment on lines 323 to 330
String count = client.newServerEval()
.xquery("let $uris := for $uri in cts:uris((), (), cts:true-query()) let $_ := xdmp:document-delete($uri) return $uri " +
"return fn:count($uris)")
.evalAs(String.class);
LoggerFactory.getLogger(ConnectedRESTQA.class).info("Cleared database, deleting {} URIs", count);
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XQuery loads all URIs into memory before deletion, which could cause memory issues with large databases. Consider using a batch processing approach or streaming deletion pattern instead of collecting all URIs at once.

Suggested change
String count = client.newServerEval()
.xquery("let $uris := for $uri in cts:uris((), (), cts:true-query()) let $_ := xdmp:document-delete($uri) return $uri " +
"return fn:count($uris)")
.evalAs(String.class);
LoggerFactory.getLogger(ConnectedRESTQA.class).info("Cleared database, deleting {} URIs", count);
int totalDeleted = 0;
while (true) {
String batchCount = client.newServerEval()
.xquery("let $batch := subsequence(cts:uris((), (), cts:true-query()), 1, 100) " +
"let $_ := for $uri in $batch return xdmp:document-delete($uri) " +
"return fn:count($batch)")
.evalAs(String.class);
int deleted = Integer.parseInt(batchCount);
totalDeleted += deleted;
LoggerFactory.getLogger(ConnectedRESTQA.class).info("Deleted {} URIs in this batch", deleted);
if (deleted < 100) {
break; // Exit loop if fewer than 100 URIs were deleted, indicating no more URIs.
}
}
LoggerFactory.getLogger(ConnectedRESTQA.class).info("Cleared database, total URIs deleted: {}", totalDeleted);

Copilot uses AI. Check for mistakes.
Comment on lines 324 to 328
.xquery("let $uris := for $uri in cts:uris((), (), cts:true-query()) let $_ := xdmp:document-delete($uri) return $uri " +
"return fn:count($uris)")
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The XQuery string is complex and embedded inline, making it difficult to read and maintain. Consider extracting this to a separate XQuery file or a well-formatted multi-line string with proper indentation.

Suggested change
.xquery("let $uris := for $uri in cts:uris((), (), cts:true-query()) let $_ := xdmp:document-delete($uri) return $uri " +
"return fn:count($uris)")
.xquery(
"let $uris := " +
" for $uri in cts:uris((), (), cts:true-query()) " +
" let $_ := xdmp:document-delete($uri) " +
" return $uri " +
"return fn:count($uris)"
)

Copilot uses AI. Check for mistakes.
The "clear" that happens via DELETE v1/search causes intermittent failures on Jenkins.
@rjrudin rjrudin force-pushed the feature/test-plumbing-fix branch from 168bfae to e9248c5 Compare July 23, 2025 14:53
@rjrudin rjrudin merged commit 6bf1119 into develop Jul 23, 2025
2 checks passed
@rjrudin rjrudin deleted the feature/test-plumbing-fix branch July 23, 2025 15:21
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