From 96955006e8a62e1bbe62b592808491bf96f4d3d1 Mon Sep 17 00:00:00 2001 From: Yun Wang Date: Mon, 17 Aug 2026 12:11:15 +0200 Subject: [PATCH] test: read the channel back when asserting partial updates The channel returned by updateChannelPartial can lag the write it just applied, so testPartialUpdateChannel and testFreezeUnfreezeChannel failed intermittently on the value they had just set. A probe over 8 rounds saw a stale partial-update response 4 times and a stale read-back none. The two tests now assert against a fresh read of the channel. --- .../getstream/ChatChannelIntegrationTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/getstream/ChatChannelIntegrationTest.java b/src/test/java/io/getstream/ChatChannelIntegrationTest.java index 37c15c1..ca73dae 100644 --- a/src/test/java/io/getstream/ChatChannelIntegrationTest.java +++ b/src/test/java/io/getstream/ChatChannelIntegrationTest.java @@ -170,7 +170,8 @@ void testPartialUpdateChannel() throws Exception { assertNotNull(setResp.getData(), "PartialUpdate (set) response should not be null"); assertNotNull(setResp.getData().getChannel(), "Channel in response should not be null"); - var custom = setResp.getData().getChannel().getCustom(); + + var custom = readChannel(channelId).getCustom(); assertNotNull(custom, "Custom data should not be null after set"); assertEquals("red", custom.get("color"), "Custom field 'color' should be 'red'"); @@ -184,12 +185,25 @@ void testPartialUpdateChannel() throws Exception { assertNotNull(unsetResp.getData(), "PartialUpdate (unset) response should not be null"); assertNotNull(unsetResp.getData().getChannel(), "Channel in response should not be null"); - var customAfterUnset = unsetResp.getData().getChannel().getCustom(); + + var customAfterUnset = readChannel(channelId).getCustom(); assertTrue( customAfterUnset == null || !customAfterUnset.containsKey("color"), "Custom field 'color' should be removed after unset"); } + /** + * Reads the channel back from the API. The channel returned by a partial update can lag the write + * it just applied, so state assertions read the channel instead of trusting that response. + */ + private ChannelResponse readChannel(String channelId) throws Exception { + return chat.getOrCreateChannel( + "messaging", channelId, GetOrCreateChannelRequest.builder().build()) + .execute() + .getData() + .getChannel(); + } + @Test @Order(9) void testAddRemoveMembers() throws Exception { @@ -793,7 +807,7 @@ void testFreezeUnfreezeChannel() throws Exception { assertNotNull(freezeResp.getData(), "Freeze response should not be null"); assertNotNull( freezeResp.getData().getChannel(), "Channel in freeze response should not be null"); - Boolean frozenAfterFreeze = freezeResp.getData().getChannel().getFrozen(); + Boolean frozenAfterFreeze = readChannel(channelId).getFrozen(); assertNotNull(frozenAfterFreeze, "Frozen field should not be null after freeze"); assertTrue(frozenAfterFreeze, "Channel should be frozen after setting frozen=true"); @@ -808,7 +822,7 @@ void testFreezeUnfreezeChannel() throws Exception { assertNotNull(unfreezeResp.getData(), "Unfreeze response should not be null"); assertNotNull( unfreezeResp.getData().getChannel(), "Channel in unfreeze response should not be null"); - Boolean frozenAfterUnfreeze = unfreezeResp.getData().getChannel().getFrozen(); + Boolean frozenAfterUnfreeze = readChannel(channelId).getFrozen(); assertNotNull(frozenAfterUnfreeze, "Frozen field should not be null after unfreeze"); assertFalse(frozenAfterUnfreeze, "Channel should be unfrozen after setting frozen=false"); }