Skip to content

Commit

Permalink
stabilize deleteRecord tests (#22)
Browse files Browse the repository at this point in the history
- adding assertions to tests to ensure insertion order

<!-- Please describe your pull request here. -->

## References

none.

<!-- References to relevant GitHub issues and pull requests, esp.
upstream and downstream changes -->

## Submitter checklist

- [ ] The PR request is well described and justified, including the body
and the references
- [ ] The PR title represents the desired changelog entry
- [ ] The repository's code style is followed (see the contributing
guide)
- [ ] Test coverage that demonstrates that the change works as expected
- [ ] For new features, there's necessary documentation in this pull
request or in a subsequent PR to
[wiremock.org](https://github.com/wiremock/wiremock.org)

<!--
Put an `x` into the [ ] to show you have filled the information.
The template comes from
https://github.com/wiremock/.github/blob/main/.github/pull_request_template.md
You can override it by creating .github/pull_request_template.md in your
own repository
-->
  • Loading branch information
dirkbolte authored Jul 28, 2023
1 parent c442f31 commit 64a8304
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/test/java/org/wiremock/extensions/state/AbstractTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import org.junit.jupiter.api.parallel.Execution;
import org.wiremock.extensions.state.internal.ContextManager;

import java.time.Duration;

import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand Down Expand Up @@ -40,4 +44,11 @@ void setupAll() {
void setupBase() {
wm.resetAll();
}

protected void assertContextNumUpdates(String context, int expected) {
await()
.pollInterval(Duration.ofMillis(10))
.atMost(Duration.ofSeconds(5)).untilAsserted(() -> assertThat(contextManager.numUpdates(context)).isEqualTo(expected));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ void test_deleteIndex_middle_ok() throws URISyntaxException {
var contextName = RandomStringUtils.randomAlphabetic(5);

postRequest("list", contextName, "one");
assertContextNumUpdates(contextName, 1);
postRequest("list", contextName, "two");
assertContextNumUpdates(contextName, 2);
postRequest("list", contextName, "three");
assertContextNumUpdates(contextName, 3);
assertList(contextName, list -> assertThat(list).hasSize(3));

getRequest("list/deleteIndex/1", contextName);
Expand All @@ -360,8 +363,11 @@ void test_deleteIndex_last_ok() throws URISyntaxException {
var contextName = RandomStringUtils.randomAlphabetic(5);

postRequest("list", contextName, "one");
assertContextNumUpdates(contextName, 1);
postRequest("list", contextName, "two");
assertContextNumUpdates(contextName, 2);
postRequest("list", contextName, "three");
assertContextNumUpdates(contextName, 3);
assertList(contextName, list -> assertThat(list).hasSize(3));

getRequest("list/deleteIndex/2", contextName);
Expand All @@ -380,8 +386,11 @@ void test_deleteWhere_middle_ok() throws URISyntaxException {
var contextName = RandomStringUtils.randomAlphabetic(5);

postRequest("list", contextName, "one");
assertContextNumUpdates(contextName, 1);
postRequest("list", contextName, "two");
assertContextNumUpdates(contextName, 2);
postRequest("list", contextName, "three");
assertContextNumUpdates(contextName, 3);
assertList(contextName, list -> assertThat(list).hasSize(3));

getRequest("list/deleteWhere/two", contextName);
Expand All @@ -400,8 +409,11 @@ void test_deleteWhere_last_ok() throws URISyntaxException {
var contextName = RandomStringUtils.randomAlphabetic(5);

postRequest("list", contextName, "one");
assertContextNumUpdates(contextName, 1);
postRequest("list", contextName, "two");
assertContextNumUpdates(contextName, 2);
postRequest("list", contextName, "three");
assertContextNumUpdates(contextName, 3);
assertList(contextName, list -> assertThat(list).hasSize(3));

getRequest("list/deleteWhere/three", contextName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ void test_initialUpdateCount_1_ok() {

postRequest("state", context, "one");

await()
.pollInterval(Duration.ofMillis(10))
.atMost(Duration.ofSeconds(2)).untilAsserted(() -> assertThat(contextManager.numUpdates(context)).isEqualTo(1));
assertContextNumUpdates(context, 1);
}

@Test
Expand All @@ -266,9 +264,7 @@ void test_multipleUpdateCount_increase_ok() {
postRequest("state", context, "one");
postRequest("state", context, "one");

await()
.pollInterval(Duration.ofMillis(10))
.atMost(Duration.ofSeconds(2)).untilAsserted(() -> assertThat(contextManager.numUpdates(context)).isEqualTo(3));
assertContextNumUpdates(context, 3);
}

@Test
Expand All @@ -280,12 +276,8 @@ void test_differentContext_ok() {
postRequest("state", contextTwo, "one");
postRequest("state", contextOne, "one");

await()
.pollInterval(Duration.ofMillis(10))
.atMost(Duration.ofSeconds(2)).untilAsserted(() -> assertThat(contextManager.numUpdates(contextOne)).isEqualTo(2));
await()
.pollInterval(Duration.ofMillis(10))
.atMost(Duration.ofSeconds(2)).untilAsserted(() -> assertThat(contextManager.numUpdates(contextTwo)).isEqualTo(1));
assertContextNumUpdates(contextOne, 2);
assertContextNumUpdates(contextTwo, 1);
}

}
Expand Down

0 comments on commit 64a8304

Please sign in to comment.