-
Notifications
You must be signed in to change notification settings - Fork 15
refactor: Improve the refresh to allow connectors to close, part of #421. #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,7 +269,9 @@ t.test('CloudSQLInstance', async t => { | |
| await CloudSQLInstance.prototype.refresh.call(instance); | ||
| instance.refresh = CloudSQLInstance.prototype.refresh; | ||
| }; | ||
|
|
||
| await instance.forceRefresh(); | ||
|
|
||
| t.ok( | ||
| cancelRefreshCalled, | ||
| 'should cancelRefresh current refresh cycle on force refresh' | ||
|
|
@@ -290,7 +292,7 @@ t.test('CloudSQLInstance', async t => { | |
| let cancelRefreshCalled = false; | ||
| let refreshCalled = false; | ||
|
|
||
| const refreshPromise = instance.refresh(); | ||
| instance.refresh(); | ||
|
|
||
| instance.cancelRefresh = () => { | ||
| cancelRefreshCalled = true; | ||
|
|
@@ -302,13 +304,7 @@ t.test('CloudSQLInstance', async t => { | |
| return CloudSQLInstance.prototype.refresh.call(instance); | ||
| }; | ||
|
|
||
| const forceRefreshPromise = instance.forceRefresh(); | ||
| t.strictSame( | ||
| refreshPromise, | ||
| forceRefreshPromise, | ||
| 'forceRefresh should return same promise ref from initial refresh call' | ||
| ); | ||
| await forceRefreshPromise; | ||
| await instance.forceRefresh(); | ||
|
|
||
| t.ok( | ||
| !cancelRefreshCalled, | ||
|
|
@@ -481,6 +477,43 @@ t.test('CloudSQLInstance', async t => { | |
| } | ||
| ); | ||
|
|
||
| t.test( | ||
| 'close on established connection and ongoing failed cycle', | ||
| async t => { | ||
| let metadataCount = 0; | ||
| const failAndSlowFetcher = { | ||
| ...fetcher, | ||
| async getInstanceMetadata() { | ||
| await (() => new Promise(res => setTimeout(res, 50)))(); | ||
| metadataCount++; | ||
| return fetcher.getInstanceMetadata(); | ||
| }, | ||
| }; | ||
|
|
||
| const instance = new CloudSQLInstance({ | ||
| ipType: IpAddressTypes.PUBLIC, | ||
| authType: AuthTypes.PASSWORD, | ||
| instanceConnectionName: 'my-project:us-east1:my-instance', | ||
| sqlAdminFetcher: failAndSlowFetcher, | ||
| limitRateInterval: 50, | ||
| }); | ||
|
|
||
| await instance.refresh(); | ||
| instance.setEstablishedConnection(); | ||
|
|
||
| // starts a new refresh cycle but do not await on it | ||
| instance.close(); | ||
| await instance.forceRefresh(); | ||
| t.equal(metadataCount, 1, 'No refresh after close'); | ||
|
Comment on lines
+504
to
+507
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this mean we do not error on a closed instance?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't throw an error from forceRefresh(). The node connector will throw an error when trying to call connect() on a closed instance, but that's coming in a later PR. |
||
|
|
||
| await t.rejects( | ||
| instance.refresh(), | ||
| 'closed', | ||
| 'Refresh after close rejected.' | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| t.test( | ||
| 'get invalid certificate data while having a current valid', | ||
| async t => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be async. Otherwise it will block the exit of the connector until the refresh is successful. This causes some failure test cases to hang and never exit.