Skip to content

Commit 655aee8

Browse files
chore(tests): clean leftover channel types + commands before tests run
ChannelTypeTest and CommandTest tear down their own state inline at the end of each test. When a CI run dies mid-test before that delete fires the shared test app keeps the leftover entries, and once enough zombies accumulate every new run hits the 50-item quota: StreamException: CreateChannelType failed with error: "your application reached the maximum number of custom channel types (50)" StreamException: CreateCommand failed with error: "your application reached the maximum number of custom commands (50)" Add a @BeforeAll sweep on both test classes that wipes non-system custom channel types / commands. Best-effort: anything in active use just returns an error and is skipped.
1 parent 027a20a commit 655aee8

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

src/test/java/io/getstream/chat/java/ChannelTypeTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@
1515
import org.junit.jupiter.api.*;
1616

1717
public class ChannelTypeTest extends BasicTest {
18+
19+
private static final java.util.Set<String> SYSTEM_CHANNEL_TYPES =
20+
java.util.Set.of("messaging", "livestream", "gaming", "commerce", "team");
21+
22+
/**
23+
* Delete zombie custom channel types left over from prior CI runs that failed mid-test before
24+
* their inline {@code ChannelType.delete(...)} could fire. The shared test app caps custom
25+
* channel types at 50; without this sweep new branches hit the quota as soon as enough zombie
26+
* types accumulate. Only deletes types not in {@link #SYSTEM_CHANNEL_TYPES}.
27+
*/
28+
@BeforeAll
29+
static void cleanupLeftoverChannelTypes() {
30+
try {
31+
var resp = ChannelType.list().request();
32+
if (resp == null || resp.getChannelTypes() == null) return;
33+
resp.getChannelTypes().keySet().stream()
34+
.filter(name -> !SYSTEM_CHANNEL_TYPES.contains(name))
35+
.forEach(
36+
name -> {
37+
try {
38+
ChannelType.delete(name).request();
39+
} catch (StreamException ignored) {
40+
// Best-effort: skip types that are in use or already deleted.
41+
}
42+
});
43+
} catch (StreamException ignored) {
44+
// Best-effort: if list fails the tests below will surface the real error.
45+
}
46+
}
47+
1848
@Test
1949
@DisplayName("Get channel type with populated commands")
2050
void whenPopulatingCommands_thenFetchChannelTypeWithoutAnyIssues() {

src/test/java/io/getstream/chat/java/CommandTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
package io.getstream.chat.java;
22

3+
import io.getstream.chat.java.exceptions.StreamException;
34
import io.getstream.chat.java.models.Command;
45
import java.util.List;
56
import org.apache.commons.lang3.RandomStringUtils;
67
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.BeforeAll;
79
import org.junit.jupiter.api.DisplayName;
810
import org.junit.jupiter.api.Test;
911

1012
public class CommandTest extends BasicTest {
1113

14+
private static final java.util.Set<String> SYSTEM_COMMANDS =
15+
java.util.Set.of("giphy", "imgur", "ban", "unban", "mute", "unmute", "flag", "unflag");
16+
17+
/**
18+
* Delete zombie custom commands left over from prior CI runs that failed mid-test before the
19+
* inline {@code Command.delete(...)} could fire. The shared test app caps custom commands at 50.
20+
* Only deletes commands not in {@link #SYSTEM_COMMANDS}.
21+
*/
22+
@BeforeAll
23+
static void cleanupLeftoverCommands() {
24+
try {
25+
var resp = Command.list().request();
26+
if (resp == null || resp.getCommands() == null) return;
27+
resp.getCommands().stream()
28+
.map(Command::getName)
29+
.filter(name -> name != null && !SYSTEM_COMMANDS.contains(name))
30+
.forEach(
31+
name -> {
32+
try {
33+
Command.delete(name).request();
34+
} catch (StreamException ignored) {
35+
// Best-effort: skip commands that are in use or already deleted.
36+
}
37+
});
38+
} catch (StreamException ignored) {
39+
// Best-effort.
40+
}
41+
}
42+
1243
@DisplayName("Can create command")
1344
@Test
1445
void whenCreatingCommand_thenCorrectDescription() {

0 commit comments

Comments
 (0)