Skip to content

Commit 44df37b

Browse files
committed
add wait
1 parent 6b6427d commit 44df37b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/test/java/org/apache/skywalking/banyandb/v1/client/BanyanDBAuthTest.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525
import org.junit.Rule;
2626
import org.junit.Test;
2727
import org.testcontainers.containers.GenericContainer;
28+
import org.testcontainers.containers.wait.strategy.Wait;
2829
import org.testcontainers.utility.DockerImageName;
2930
import org.testcontainers.utility.MountableFile;
3031

3132
import java.io.IOException;
33+
import java.time.Duration;
34+
import java.util.Base64;
3235
import java.util.List;
36+
import java.util.concurrent.TimeUnit;
3337

38+
import static org.awaitility.Awaitility.await;
3439
import static org.junit.Assert.assertThrows;
3540

3641
public class BanyanDBAuthTest {
@@ -39,6 +44,7 @@ public class BanyanDBAuthTest {
3944
private static final String TAG = "42ec9df7457868926eb80157b36355d94fcd6bba";
4045

4146
private static final String IMAGE = REGISTRY + "/" + IMAGE_NAME + ":" + TAG;
47+
private static final String AUTH = Base64.getEncoder().encodeToString("admin:123456".getBytes());
4248

4349
protected static final int GRPC_PORT = 17912;
4450
protected static final int HTTP_PORT = 17913;
@@ -53,25 +59,33 @@ public class BanyanDBAuthTest {
5359
"--auth-config-file", "/tmp/bydb_server_config.yaml",
5460
"--enable-health-auth", "true"
5561
)
56-
.withExposedPorts(GRPC_PORT, HTTP_PORT);
57-
// TODO .waitingFor(Wait.forLogMessage(".*\"message\":\"Listening to\".*", 1));
62+
.withExposedPorts(GRPC_PORT, HTTP_PORT)
63+
.waitingFor(Wait.forHttp("/api/healthz")
64+
.forPort(HTTP_PORT)
65+
.withHeader("Authorization", "Basic " + AUTH)
66+
.forStatusCode(200)
67+
.withStartupTimeout(Duration.ofSeconds(30)));
5868

5969
@Test
6070
public void testAuthWithCorrect() throws BanyanDBException, IOException {
6171
BanyanDBClient client = createClient("admin", "123456");
6272
client.connect();
63-
// list all groups
64-
List<BanyandbCommon.Group> groupList = client.findGroups();
65-
Assert.assertEquals(1, groupList.size());
66-
Assert.assertEquals("_monitoring", groupList.get(0).getMetadata().getName());
73+
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
74+
// list all groups
75+
List<BanyandbCommon.Group> groupList = client.findGroups();
76+
Assert.assertEquals(1, groupList.size());
77+
Assert.assertEquals("_monitoring", groupList.get(0).getMetadata().getName());
78+
});
6779
client.close();
6880
}
6981

7082
@Test
7183
public void testAuthWithWrong() throws IOException {
7284
BanyanDBClient client = createClient("admin", "123456" + "wrong");
7385
client.connect();
74-
assertThrows(UnauthenticatedException.class, client::getAPIVersion);
86+
await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> {
87+
assertThrows(UnauthenticatedException.class, client::getAPIVersion);
88+
});
7589
client.close();
7690
}
7791

0 commit comments

Comments
 (0)