|
23 | 23 | import java.util.logging.Logger; |
24 | 24 | import org.apache.commons.lang3.RandomStringUtils; |
25 | 25 | import org.junit.jupiter.api.Assertions; |
| 26 | +import org.junit.jupiter.api.BeforeAll; |
26 | 27 | import org.junit.jupiter.api.DisplayName; |
27 | 28 | import org.junit.jupiter.api.Test; |
28 | 29 | import org.junit.jupiter.api.function.ThrowingSupplier; |
29 | 30 |
|
30 | 31 | public class UserTest extends BasicTest { |
31 | 32 |
|
| 33 | + /** |
| 34 | + * Clear zombie bans left over from prior CI runs that died before their cleanup could fire. |
| 35 | + * {@code User.queryBanned().request()} returns a paginated slice; once enough bans accumulate on |
| 36 | + * the shared test app, the just-created ban under test ends up past the first page and the {@code |
| 37 | + * assertTrue(bans.stream().anyMatch(...))} assertion fails. Best-effort sweep. |
| 38 | + */ |
| 39 | + @BeforeAll |
| 40 | + static void cleanupLeftoverBans() { |
| 41 | + // queryBanned() returns a paginated slice, so a single pass only clears |
| 42 | + // the first page. Loop until either the response is empty or we stop |
| 43 | + // making progress; cap iterations to avoid running forever against a |
| 44 | + // poisoned app. |
| 45 | + Set<String> seen = new HashSet<>(); |
| 46 | + for (int round = 0; round < 20; round++) { |
| 47 | + List<Ban> bans; |
| 48 | + try { |
| 49 | + bans = User.queryBanned().request().getBans(); |
| 50 | + } catch (StreamException ignored) { |
| 51 | + return; // Best-effort. |
| 52 | + } |
| 53 | + if (bans == null || bans.isEmpty()) return; |
| 54 | + int unbannedThisRound = 0; |
| 55 | + for (var ban : bans) { |
| 56 | + if (ban.getUser() == null || ban.getUser().getId() == null) continue; |
| 57 | + String id = ban.getUser().getId(); |
| 58 | + if (!seen.add(id)) continue; |
| 59 | + try { |
| 60 | + User.unban(id).request(); |
| 61 | + unbannedThisRound++; |
| 62 | + } catch (StreamException ignored) { |
| 63 | + // In-use or already-deleted; skip. |
| 64 | + } |
| 65 | + } |
| 66 | + if (unbannedThisRound == 0) return; // No progress; bail. |
| 67 | + } |
| 68 | + } |
| 69 | + |
32 | 70 | @DisplayName("Can list users with no Exception") |
33 | 71 | @Test |
34 | 72 | void whenListingUsers_thenNoException() { |
|
0 commit comments