<commit_before>package io.dropwizard.testing.junit5;

import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.concurrent.ConcurrentSkipListSet;

import static org.assertj.core.api.Assertions.assertThat;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(DropwizardExtensionsSupport.class)
class ResourceExtensionRandomPortsTest {
    private final ResourceExtension resources = ResourceExtension.builder()
            .setTestContainerFactory(new GrizzlyTestContainerFactory())
            .build();

    ConcurrentSkipListSet<Integer> usedPorts = new ConcurrentSkipListSet<>();

    @RepeatedTest(10)
    public void eachTestShouldUseANewPort() {
        final int port = resources.target("/").getUri().getPort();
        assertThat(usedPorts).doesNotContain(port);

        usedPorts.add(port);
    }
}<commit_msg>Make `ResourceExtensionRandomPortsTest` less flaky (#3897)<commit_after>package io.dropwizard.testing.junit5;

import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

class ResourceExtensionRandomPortsTest {

    @Test
    public void eachTestShouldUseANewPort() throws Throwable {
        final ResourceExtension resources = ResourceExtension.builder()
                .setTestContainerFactory(new GrizzlyTestContainerFactory())
                .build();
        Set<Integer> usedPorts = new HashSet<>();

        for (int i = 0; i < 10; i++) {
            resources.before();
            final int port = resources.target("/").getUri().getPort();
            usedPorts.add(port);
        }
        assertThat(usedPorts).hasSizeGreaterThanOrEqualTo(2);
    }
}
{'fraction_non_alphanumeric': 0.10606060606060606, 'fraction_numerical': 0.006269592476489028, 'mean_word_length': 4.026246719160105, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6725808', 'n_tokens_mistral': 569, 'n_tokens_neox': 553, 'n_words': 91}