Skip to content

Commit c99636f

Browse files
authored
Use global lock for auth credential access in tests. (#2038)
* Use global lock for auth credential access. * add timeout
1 parent 0d8f5b3 commit c99636f

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

.changeset/seven-rabbits-poke.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.github/workflows/health_checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ jobs:
436436
check_package_versions:
437437
if: github.event_name == 'pull_request'
438438
runs-on: ubuntu-latest
439+
timeout-minutes: 10
439440
needs:
440441
- install
441442
steps:

packages/integration-tests/src/amplify_auth_credentials_factory.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ import { AsyncLock } from './async_lock.js';
1616
* This class is safe to use in concurrent settings, i.e. tests running in parallel.
1717
*/
1818
export class AmplifyAuthCredentialsFactory {
19-
private readonly userPoolId: string;
20-
private readonly userPoolClientId: string;
21-
private readonly identityPoolId: string;
22-
private readonly allowGuestAccess: boolean | undefined;
2319
/**
2420
* Asynchronous lock is used to assure that all calls to Amplify JS library are
2521
* made in single transaction. This is because that library maintains global state,
2622
* for example auth session.
2723
*/
28-
private readonly lock: AsyncLock = new AsyncLock(60 * 1000);
24+
private static readonly lock: AsyncLock = new AsyncLock(60 * 1000);
25+
26+
private readonly userPoolId: string;
27+
private readonly userPoolClientId: string;
28+
private readonly identityPoolId: string;
29+
private readonly allowGuestAccess: boolean | undefined;
2930

3031
/**
3132
* Creates Amplify Auth credentials factory.
@@ -47,7 +48,7 @@ export class AmplifyAuthCredentialsFactory {
4748
iamCredentials: IamCredentials;
4849
accessToken: string;
4950
}> => {
50-
await this.lock.acquire();
51+
await AmplifyAuthCredentialsFactory.lock.acquire();
5152
try {
5253
const username = `amplify-backend-${shortUuid()}@amazon.com`;
5354
const temporaryPassword = `Test1@Temp${shortUuid()}`;
@@ -103,12 +104,12 @@ export class AmplifyAuthCredentialsFactory {
103104
accessToken: authSession.tokens.accessToken.toString(),
104105
};
105106
} finally {
106-
this.lock.release();
107+
AmplifyAuthCredentialsFactory.lock.release();
107108
}
108109
};
109110

110111
getGuestAccessCredentials = async (): Promise<IamCredentials> => {
111-
await this.lock.acquire();
112+
await AmplifyAuthCredentialsFactory.lock.acquire();
112113
try {
113114
Amplify.configure({
114115
Auth: {
@@ -131,7 +132,7 @@ export class AmplifyAuthCredentialsFactory {
131132

132133
return authSession.credentials;
133134
} finally {
134-
this.lock.release();
135+
AmplifyAuthCredentialsFactory.lock.release();
135136
}
136137
};
137138
}

0 commit comments

Comments
 (0)