Core: thread-safe initialization for GoogleAuthManager#16848
Core: thread-safe initialization for GoogleAuthManager#16848vladislav-sidorovich wants to merge 1 commit into
Conversation
| } | ||
|
|
||
| startLatch.countDown(); | ||
| finishLatch.await(10, TimeUnit.SECONDS); |
There was a problem hiding this comment.
Probably should assert the return value of await() is true?
There was a problem hiding this comment.
I'm not 100% sure about it, let's discuss.
Java doc:
Returns:
true if the count reached zero and false if the waiting time elapsed before the count reached zero
So, in my opinion the test should fail on the verify(spyManager, times(1)) but not on the fact that the wait time > 10 seconds.
What do you think?
Note: actually in other tests in Iceberg it works without isTrue.
| } | ||
|
|
||
| startLatch.countDown(); | ||
| finishLatch.await(10, TimeUnit.SECONDS); |
There was a problem hiding this comment.
| finishLatch.await(10, TimeUnit.SECONDS); | |
| assertThat(finishLatch.await(10, TimeUnit.SECONDS)).isTrue(); |
| GoogleAuthManager spyManager = spy(authManager); | ||
| doReturn(credentials) | ||
| .when(spyManager) | ||
| .loadCredentials(anyBoolean(), any(), anyBoolean(), any(), any()); |
There was a problem hiding this comment.
The test probably won't catch the bug you fixed because it returns value quickly? In other words, does this test reliably fail without the fix?
There was a problem hiding this comment.
Yes, the test will fail. I commented the synchronyzed section and run the test. The test failed with the following error:
googleAuthManager.loadCredentials(
<any boolean>,
<any>,
<any boolean>,
<any>,
<any>
);
Wanted 1 time:
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.loadCredentials(GoogleAuthManager.java:128)
But was 10 times:
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
-> at org.apache.iceberg.gcp.auth.GoogleAuthManager.initialize(GoogleAuthManager.java:105)
Make initialization for
GoogleAuthManagerthread-sage.