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

[3.2] Fix service binding PostgreSQL tests on OpenShift 4.14 as cluster service versions are loaded lazily #1547

Merged
merged 1 commit into from
Nov 28, 2023
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package io.quarkus.ts.sb.postgresql;

import static io.quarkus.test.utils.AwaitilityUtils.untilAsserted;
import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings.using;
import static java.time.Duration.ofSeconds;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jakarta.inject.Inject;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
Expand Down Expand Up @@ -47,22 +50,23 @@ public void verifyPostgresServiceBoundToApplication() {
.statusCode(HttpStatus.SC_OK);
}

private static boolean areRequiredOperatorsInstalled() {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some time for API to
// populate new namespace with objects
Thread.sleep(2000);
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
String outputString = output.stream().collect(Collectors.joining(System.lineSeparator()));
return (outputString.contains("postgresoperator") && outputString.contains("service-binding-operator"));
private static void assertRequiredOperatorsInstalled() {
untilAsserted(() -> {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some
// time for API to populate new namespace with objects
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
assertTrue(output.stream().anyMatch(str -> str.contains("postgresoperator")));
assertTrue(output.stream().anyMatch(str -> str.contains("service-binding-operator")));
}, using(ofSeconds(2), ofSeconds(60)));
}

private static void createPostgresCluster() {
Assumptions.assumeTrue(areRequiredOperatorsInstalled());
assertRequiredOperatorsInstalled();
applyCustomResourceDefinition("pg-cluster.yml");
try {
// TODO: figure out a better way to wait for this - sometimes operator takes a while to create object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package io.quarkus.ts.sb.reactive;

import static io.quarkus.test.utils.AwaitilityUtils.untilAsserted;
import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings.using;
import static java.time.Duration.ofSeconds;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jakarta.inject.Inject;

import org.apache.http.HttpStatus;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
Expand Down Expand Up @@ -51,22 +54,23 @@ public void verifyPostgresServiceBoundToApplication() {
.body("title", Matchers.equalTo("Finish the blog post"));
}

private static boolean areRequiredOperatorsInstalled() {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some time for API to
// populate new namespace with objects
Thread.sleep(2000);
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
String outputString = output.stream().collect(Collectors.joining(System.lineSeparator()));
return (outputString.contains("postgresoperator") && outputString.contains("service-binding-operator"));
private static void assertRequiredOperatorsInstalled() {
untilAsserted(() -> {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some
// time for API to populate new namespace with objects
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
assertTrue(output.stream().anyMatch(str -> str.contains("postgresoperator")));
assertTrue(output.stream().anyMatch(str -> str.contains("service-binding-operator")));
}, using(ofSeconds(2), ofSeconds(60)));
}

private static void createPostgresCluster() {
Assumptions.assumeTrue(areRequiredOperatorsInstalled());
assertRequiredOperatorsInstalled();
applyCustomResourceDefinition();
try {
// TODO: figure out a better way to wait for this - sometimes operator takes a while to create object
Expand Down