Skip to content
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

Add Assertion to the SharedTimerTest #2381

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/test/java/com/microsoft/sqlserver/jdbc/SharedTimerTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package com.microsoft.sqlserver.jdbc;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;

import java.util.ArrayList;
import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.jupiter.api.Test;


class SharedTimerTest {

@Test
void getTimer() throws InterruptedException, ExecutionException, TimeoutException {
final int iterations = 500;

ExecutorService executor = Executors.newFixedThreadPool(2);

try {
ArrayList<CompletableFuture<?>> futures = new ArrayList<>(iterations);
for (int i = 0; i < iterations; i++) {
Expand All @@ -22,6 +29,13 @@ void getTimer() throws InterruptedException, ExecutionException, TimeoutExceptio
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(2, TimeUnit.MINUTES);
} finally {
executor.shutdown();
// 5000ms wait time for the AzureDB connection to close, need full test in the
// test lab for the exact time
if (!executor.awaitTermination(5000, TimeUnit.MILLISECONDS)) {
executor.shutdownNow();
Jeffery-Wasty marked this conversation as resolved.
Show resolved Hide resolved
}
}

assertFalse(SharedTimer.isRunning(), TestResource.getResource("R_sharedTimerStopOnNoRef"));
}
}
4 changes: 2 additions & 2 deletions src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ protected Object[][] getContents() {
{"R_invalidClientSecret", "AADSTS7000215: Invalid client secret provided"},
{"R_invalidCertFields",
"Error reading certificate, please verify the location of the certificate.signed fields invalid"},
{"R_invalidAADAuth",
"Failed to authenticate the user {0} in Active Directory (Authentication={1})"},
{"R_invalidAADAuth", "Failed to authenticate the user {0} in Active Directory (Authentication={1})"},
{"R_failedValidate", "failed to validate values in $0} "}, {"R_tableNotDropped", "table not dropped. "},
{"R_connectionReset", "Connection reset"}, {"R_unknownException", "Unknown exception"},
{"R_deadConnection", "Dead connection should be invalid"},
Expand Down Expand Up @@ -213,6 +212,7 @@ protected Object[][] getContents() {
{"R_objectNullOrEmpty", "The {0} is null or empty."},
{"R_cekDecryptionFailed", "Failed to decrypt a column encryption key using key store provider: {0}."},
{"R_connectTimedOut", "connect timed out"},
{"R_sharedTimerStopOnNoRef", "SharedTimer should be stopped after all references are removed."},
{"R_sessionKilled", "Cannot continue the execution because the session is in the kill state"},
{"R_failedFedauth", "Failed to acquire fedauth token: "},
{"R_noLoginModulesConfiguredForJdbcDriver",
Expand Down
Loading