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

Better test robustness #1549

Merged
merged 1 commit into from
May 13, 2024
Merged
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
Expand Up @@ -33,6 +33,7 @@
import static org.csanchez.jenkins.plugins.kubernetes.KubernetesTestUtil.getLabels;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.oneOf;
Expand All @@ -55,6 +56,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import java.io.IOException;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -773,28 +775,26 @@ public void secretMaskingWindows() throws Exception {

@Test
public void dynamicPVCWorkspaceVolume() throws Exception {
assumePvcAccess();
var client = cloud.connect();
var podSize = client.pods().list().getItems().size();
var pvcSize = client.persistentVolumeClaims().list().getItems().size();
r.assertBuildStatusSuccess(r.waitForCompletion(b));
await("The number of pods should be the same as before building")
.until(() -> client.pods().list().getItems(), hasSize(podSize));
await("The number of PVCs should be the same as before building")
.until(() -> client.persistentVolumeClaims().list().getItems(), hasSize(pvcSize));
dynamicPVC();
}

@Test
public void dynamicPVCVolume() throws Exception {
dynamicPVC();
}

private void dynamicPVC() throws Exception {
assumePvcAccess();
var client = cloud.connect();
var podSize = client.pods().list().getItems().size();
var pvcSize = client.persistentVolumeClaims().list().getItems().size();
r.assertBuildStatusSuccess(r.waitForCompletion(b));
await("The number of pods should be the same as before building")
.until(() -> client.pods().list().getItems(), hasSize(podSize));
await("The number of PVCs should be the same as before building")
.until(() -> client.persistentVolumeClaims().list().getItems(), hasSize(pvcSize));
var pods = client.pods().list().getItems();
var pvcs = client.persistentVolumeClaims().list().getItems();
r.assertBuildStatusSuccess(r.waitForCompletion(b));
await("The pods should be the same as before building")
.timeout(Duration.ofMinutes(1))
.until(() -> client.pods().list().getItems(), equalTo(pods));
await("The PVCs should be the same as before building")
.timeout(Duration.ofMinutes(1))
.until(() -> client.persistentVolumeClaims().list().getItems(), equalTo(pvcs));
}

private void assumePvcAccess() throws KubernetesAuthException, IOException {
Expand Down