fix(spanner): preserve user call options in execute/read and consolidate test databases#9329
fix(spanner): preserve user call options in execute/read and consolidate test databases#9329cy-yun wants to merge 9 commits into
Conversation
d69b03a to
169514a
Compare
bfd11cb to
41272ef
Compare
| // Poll for completion with the extended timeout | ||
| $op->pollUntilComplete([ | ||
| $op->pollUntilComplete( | ||
| [ |
There was a problem hiding this comment.
Did the linter suggested this change? This change feels wrong to me. I mean it still is valid, but I would expect either the previous iteration or something like:
$op->pollUntilComplete(
[
'timeoutMillis' => ...
]
)As it is right now, having the braces on the same level as the key feels off.
There was a problem hiding this comment.
But I still think the previous one should be valid 🤷
There was a problem hiding this comment.
I fixed the formatting of the code such that it is consistent with the original & phpcbf is not upset
|
|
||
| $this->assertTrue($backup->exists()); | ||
| // Cancellation usually drops the backup. We don't assert exists() | ||
| // to avoid flakiness with asynchronous deletion. |
There was a problem hiding this comment.
Wait, isn't this testing that if you execute a backup deletion and cancel it, it shouldn't be still available? Or am i misreading the test?
There was a problem hiding this comment.
Actually, this test is meant to test canceling a backup creation operation, not a deletion. Previously, the test was calling $op->pollUntilComplete() before $op->cancel(). That meant it was waiting for the backup to fully finish creating, and then issuing a cancel command on a completed operation (which basically does nothing), hence why it used to assert that the backup still existed.
By removing the polling, we are now properly canceling the operation while it is still in-progress. Because we cancelled it mid-flight, Spanner usually drops the incomplete backup, so asserting that it still exists makes the test extremely flaky.
41272ef to
2e68fb4
Compare
2e68fb4 to
921a05c
Compare
921a05c to
122401c
Compare
5798d9e to
1de72fc
Compare
1de72fc to
06d7dd9
Compare
06d7dd9 to
b81c04e
Compare
92f159b to
cd9613c
Compare
b36da9c to
2838cc6
Compare
bshaffer
left a comment
There was a problem hiding this comment.
I know this is still in Draft mode but a few things jumped out at me so I wanted to go ahead and comment on them
| if (isset($args['method'])) { | ||
| $operationResponse = $this->gapicClient->resumeOperation($args['name'], $args['method']); | ||
| } else { | ||
| $operationResponse = $this->gapicClient->resumeOperation($args['name']); | ||
| } |
There was a problem hiding this comment.
these can all be simplied
| if (isset($args['method'])) { | |
| $operationResponse = $this->gapicClient->resumeOperation($args['name'], $args['method']); | |
| } else { | |
| $operationResponse = $this->gapicClient->resumeOperation($args['name']); | |
| } | |
| $operationResponse = $this->gapicClient->resumeOperation($args['name'], $args['method'] ?? null); |
| public function resumeOperation($operationName, $methodName = null) | ||
| { | ||
| $options = $this->descriptors[$methodName]['longRunning'] ?? []; | ||
| $options = isset($methodName) ? ($this->descriptors[$methodName]['longRunning'] ?? []) : []; |
There was a problem hiding this comment.
Hmm, I do not see a functional difference between these two lines which were changed. I think this needs to be reverted.
It's also a generated file so it shouldn't be part of this PR anyway, but would need to be a change in the GAPIC generator
| public function resumeOperation($operationName, $methodName = null) | ||
| { | ||
| $options = $this->descriptors[$methodName]['longRunning'] ?? []; | ||
| $options = isset($methodName) ? ($this->descriptors[$methodName]['longRunning'] ?? []) : []; |
There was a problem hiding this comment.
Same here, I think this change should be reverted
| } catch (\Throwable $rollbackException) { | ||
| // ignore rollback failure and bubble up the original exception | ||
| } | ||
| } |
Fix Spanner System Tests Reliability and Provisioning Overhead
This PR addresses the ongoing flakiness and high database provisioning overhead of the Spanner system tests (resolving #9230).
While this PR consolidates test database provisioning (reducing overall execution time by reusing databases), the test suite as a whole will still take a long time to run (~1.5 hours) due to the inherent slowness of operations like Backup and Restore. (Parallelizing these tests with
paratestto bring the time down to minutes is planned for a subsequent follow-up).Below is a breakdown of the specific problems and fixes implemented in this PR:
1. Dropped
$optionsArray (FixingReadTestflakiness & SDK Bug)$optionsarray was inadvertently being omitted when making calls throughDatabase::execute()andTransactionalReadTraitmethods. In the test suite, this surfaced as flakiness intestReadFailsOnDeadlineExceeded(because the 1mstimeoutMillisoption was not passed through, allowing the request to reach the backend). For users, this meant that custom RPC settings (likerequestTimeout,headers, orretrySettings) passed to queries or reads were not being applied to the underlying gRPC requests.Fix:
timeoutMillisandrequestOptionsexplicitly from$optionsinDatabase::execute,Database::read,TransactionalReadTrait::execute, andTransactionalReadTrait::read.$optionsarray (which contains internal tracking state that would otherwise cause "Unexpected option" fatal errors inOptionsValidator).2. Test Database Provisioning Overhead
TestDatabaseManagerto provision a single shared Spanner test database and reuse it across all test classes.3. PostgreSQL DDL Compatibility
CREATE TABLEcommands to fail because the tables already existed.IF NOT EXISTSto PostgreSQL DDL statements in thePg*Testclasses.4. Emulator Transaction Leaks
testLockHintReadWriteTransactionwas leaving a transaction hanging without rollback.$res->transaction()->rollback()totestLockHintReadWriteTransaction, and added an unhandled exception catch block inDatabase::runTransactionto rollback non-single-use active transactions before bubbling up the exception.5.
BackupTestReliabilityBackupTestoperations were flaking due to transient errors and improper polling configurations (e.g.timeoutMillisinstead ofmaxPollingDurationSecondsfor GAX long-running operations). The backup cancellation test was also flawed because it tried to wait for a cancelled backup to exist.maxPollingDurationSeconds. Added retry logic forUNAVAILABLEerrors intestRestoreDatabase. Split the backup creation and cancellation tests to prevent the cancellation from interfering with tests that depend on a successfully created backup.6. PHP 8.1 Deprecation Warnings
nullto non-nullable internal string parameters threw deprecation warnings in PHP 8.1 (e.g. inValueMapper). Additionally, themethodkey was sometimes missing when resuming operations in admin clients.ValueMapperand addedissetchecks formethodinLongRunningClientConnectionand*AdminClient.7. CI Configuration
phpunit-system.xml.dist.