Skip to content

Conversation

@Sineaggi
Copy link
Contributor

@Sineaggi Sineaggi commented Aug 21, 2023

I've noticed a single test failing now and then on my MR #2041

Expected: is <1>
     but: was <0>

@Sineaggi Sineaggi requested a review from a team as a code owner August 21, 2023 19:13
@eddumelendez eddumelendez changed the title Add wait for flaky test Improve assertions Oct 26, 2023
@eddumelendez
Copy link
Member

@Sineaggi Thanks for your contribution! I already merged #2188. Can you please update your PR? Let's keep this one as an improvement for assertions

@eddumelendez eddumelendez added this to the next milestone Oct 26, 2023
diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java
index c03df2a..3066767 100644
--- a/docker-java/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java
+++ b/docker-java/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java
@@ -26,11 +26,12 @@ import static java.util.Collections.singletonList;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.emptyString;
-import static org.hamcrest.Matchers.isOneOf;
 import static org.hamcrest.Matchers.not;
 import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.oneOf;
 import static org.hamcrest.Matchers.startsWith;
 import static org.junit.Assert.assertEquals;
 import static org.testinfected.hamcrest.jpa.PersistenceMatchers.hasField;
@@ -161,8 +162,8 @@ public class ListContainersCmdIT extends CmdIT {
                 .exec();

         assertThat(filteredContainers.size(), is(2));
-        assertThat(filteredContainers.get(0).getId(), isOneOf(id1, id2));
-        assertThat(filteredContainers.get(1).getId(), isOneOf(id1, id2));
+        assertThat(filteredContainers.get(0).getId(), is(oneOf(id1, id2)));
+        assertThat(filteredContainers.get(1).getId(), is(oneOf(id1, id2)));
     }

     @test
@@ -184,8 +185,8 @@ public class ListContainersCmdIT extends CmdIT {
                 .exec();

         assertThat(filteredContainers.size(), is(2));
-        assertThat(filteredContainers.get(0).getId(), isOneOf(id1, id2));
-        assertThat(filteredContainers.get(1).getId(), isOneOf(id1, id2));
+        assertThat(filteredContainers.get(0).getId(), is(oneOf(id1, id2)));
+        assertThat(filteredContainers.get(1).getId(), is(oneOf(id1, id2)));
     }

     @test
@@ -219,7 +220,7 @@ public class ListContainersCmdIT extends CmdIT {
                 .withStatusFilter(singletonList("running"))
                 .exec();

-        assertThat(filteredContainers.size(), is(1));
+        assertThat(filteredContainers, hasSize(1));
         assertThat(filteredContainers.get(0).getId(), is(containerId));
     }

@@ -239,7 +240,7 @@ public class ListContainersCmdIT extends CmdIT {
                 .withStatusFilter(singletonList("paused"))
                 .exec();

-        assertThat(filteredContainers.size(), is(1));
+        assertThat(filteredContainers, hasSize(1));
         assertThat(filteredContainers.get(0).getId(), is(containerId));
     }

@@ -260,7 +261,7 @@ public class ListContainersCmdIT extends CmdIT {
                 .withStatusFilter(singletonList("exited"))
                 .exec();

-        assertThat(filteredContainers.size(), is(1));
+        assertThat(filteredContainers, hasSize(1));
         assertThat(filteredContainers.get(0).getId(), is(containerId));
     }

@@ -289,7 +290,7 @@ public class ListContainersCmdIT extends CmdIT {
                 .withVolumeFilter(singletonList("TestFilterVolume"))
                 .exec();

-        assertThat(filteredContainers.size(), is(1));
+        assertThat(filteredContainers, hasSize(1));
         assertThat(filteredContainers.get(0).getId(), is(id));
     }
@Sineaggi
Copy link
Contributor Author

Sineaggi commented Oct 27, 2023

@eddumelendez I've rebased the pr.

@eddumelendez eddumelendez merged commit 278a3ac into docker-java:main Oct 27, 2023
@eddumelendez
Copy link
Member

Thanks for your contribution, @Sineaggi !

@Sineaggi Sineaggi deleted the it-cleanup branch October 27, 2023 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants