fix: make test_utils unique_resource_id parallel-safe#17440
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the unique_resource_id helper in google-cloud-testutils to automatically include the process ID (PID) in the generated ID, and simplifies the Firestore system tests which previously appended the PID manually. It also updates the Firestore post-processing configuration and noxfile.py to treat google-cloud-testutils as a local dependency. The review feedback suggests using millisecond resolution (1000 * time.time()) instead of second resolution in the CI environment path of unique_resource_id to prevent potential resource ID collisions when multiple resources are created within the same second.
| else: | ||
| return "%s%s%s%d" % (delimiter, build_id, delimiter, time.time()) | ||
| return "%s%s%s%d%s%d" % (delimiter, build_id, delimiter, time.time(), delimiter, pid) |
There was a problem hiding this comment.
In CI environments (where build_id is present), using time.time() with %d formatting provides only 1-second resolution. If a test suite or parallel workers within the same build create multiple unique resources within the same second, this can lead to resource ID collisions.
Using millisecond resolution (1000 * time.time()) in the else block, consistent with the if block, will significantly reduce the likelihood of such collisions.
| else: | |
| return "%s%s%s%d" % (delimiter, build_id, delimiter, time.time()) | |
| return "%s%s%s%d%s%d" % (delimiter, build_id, delimiter, time.time(), delimiter, pid) | |
| else: | |
| return "%s%s%s%d%s%d" % (delimiter, build_id, delimiter, 1000 * time.time(), delimiter, pid) |
This PR shifts the parallel-safety logic (
os.getpid()) out of the individual firestore system tests, baking it directly into the sharedtest_utilspackage.This ensures that all packages in the monorepo using pytest-xdist will automatically generate unique collection/resource names that never collide across parallel workers, rather than requiring each library to manually append PID strings to
unique_resource_id().