-
Notifications
You must be signed in to change notification settings - Fork 27
Add configurable WebSocket buffer sizes for large Nostr events #505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4866ce4
feat(websocket): add configurable buffer sizes for large Nostr events
916dd04
chore(release): bump version 1.2.1 → 1.3.0
aed3adf
test(ws): add tests for message accumulation and timeout behavior in …
58153ed
Initial plan
Copilot e68ec39
chores: Update CHANGELOG.md
tcheeric 1bf8954
fix: Update CHANGELOG.md
tcheeric 1c42ad3
Initial plan
Copilot e97f4ec
Initial plan
Copilot b290c3a
Initial plan
Copilot 4dba87f
Merge pull request #509 from tcheeric/copilot/sub-pr-505-yet-again
tcheeric 628f66a
Merge pull request #508 from tcheeric/copilot/sub-pr-505-another-one
tcheeric a2c93f8
Merge pull request #507 from tcheeric/copilot/sub-pr-505-again
tcheeric 47384fe
Merge pull request #506 from tcheeric/copilot/sub-pr-505
tcheeric aa9a7ef
fix(ci): allow CI to run on develop branch in addition to main
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...t/src/test/java/nostr/client/springwebsocket/StandardWebSocketClientMultiMessageTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package nostr.client.springwebsocket; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
| import org.springframework.web.socket.TextMessage; | ||
| import org.springframework.web.socket.WebSocketSession; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.doAnswer; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| /** | ||
| * Tests that StandardWebSocketClient correctly accumulates multiple messages | ||
| * before completing when a termination message (EOSE, OK) is received. | ||
| */ | ||
| class StandardWebSocketClientMultiMessageTest { | ||
|
|
||
| @Test | ||
| void testAccumulatesMessagesUntilEose() throws Exception { | ||
| WebSocketSession session = Mockito.mock(WebSocketSession.class); | ||
| when(session.isOpen()).thenReturn(true); | ||
|
|
||
| StandardWebSocketClient client = new StandardWebSocketClient(session, 5000, 100); | ||
|
|
||
| // Simulate relay responses when send is called | ||
| CountDownLatch sendLatch = new CountDownLatch(1); | ||
| doAnswer(invocation -> { | ||
| sendLatch.countDown(); | ||
| return null; | ||
| }).when(session).sendMessage(any(TextMessage.class)); | ||
|
|
||
| // Start send in background thread | ||
| Thread sendThread = new Thread(() -> { | ||
| try { | ||
| List<String> result = client.send("[\"REQ\",\"sub1\",{}]"); | ||
| assertEquals(2, result.size(), "Should receive EVENT + EOSE"); | ||
| assertTrue(result.get(0).contains("EVENT"), "First message should be EVENT"); | ||
| assertTrue(result.get(1).contains("EOSE"), "Second message should be EOSE"); | ||
| } catch (Exception e) { | ||
tcheeric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
| sendThread.start(); | ||
|
|
||
| // Wait for send to start | ||
| assertTrue(sendLatch.await(1, TimeUnit.SECONDS), "Send should have started"); | ||
| Thread.sleep(50); // Small delay for send() to set up pendingRequest | ||
|
|
||
| // Simulate EVENT message (not termination - should NOT complete) | ||
| client.handleTextMessage(session, new TextMessage("[\"EVENT\",\"sub1\",{\"id\":\"abc\"}]")); | ||
|
|
||
| // Small delay to ensure processing | ||
| Thread.sleep(50); | ||
|
|
||
| // Simulate EOSE message (termination - should complete) | ||
| client.handleTextMessage(session, new TextMessage("[\"EOSE\",\"sub1\"]")); | ||
|
|
||
| // Wait for send thread to complete | ||
| sendThread.join(2000); | ||
| } | ||
tcheeric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Test | ||
| void testCompletesImmediatelyOnOk() throws Exception { | ||
| WebSocketSession session = Mockito.mock(WebSocketSession.class); | ||
| when(session.isOpen()).thenReturn(true); | ||
|
|
||
| StandardWebSocketClient client = new StandardWebSocketClient(session, 5000, 100); | ||
|
|
||
| CountDownLatch sendLatch = new CountDownLatch(1); | ||
| doAnswer(invocation -> { | ||
| sendLatch.countDown(); | ||
| return null; | ||
| }).when(session).sendMessage(any(TextMessage.class)); | ||
|
|
||
| Thread sendThread = new Thread(() -> { | ||
| try { | ||
| List<String> result = client.send("[\"EVENT\",{\"id\":\"abc\"}]"); | ||
| assertEquals(1, result.size(), "Should receive just OK"); | ||
| assertTrue(result.get(0).contains("OK"), "Message should be OK"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
| sendThread.start(); | ||
|
|
||
| assertTrue(sendLatch.await(1, TimeUnit.SECONDS)); | ||
| Thread.sleep(50); | ||
|
|
||
| // Simulate OK message (termination - should complete immediately) | ||
| client.handleTextMessage(session, new TextMessage("[\"OK\",\"abc\",true,\"\"]")); | ||
|
|
||
| sendThread.join(2000); | ||
| } | ||
tcheeric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Test | ||
| void testEventWithoutEoseTimesOut() throws Exception { | ||
| WebSocketSession session = Mockito.mock(WebSocketSession.class); | ||
| when(session.isOpen()).thenReturn(true); | ||
|
|
||
| // Short timeout for this test | ||
| StandardWebSocketClient client = new StandardWebSocketClient(session, 200, 50); | ||
|
|
||
| CountDownLatch sendLatch = new CountDownLatch(1); | ||
| doAnswer(invocation -> { | ||
| sendLatch.countDown(); | ||
| return null; | ||
| }).when(session).sendMessage(any(TextMessage.class)); | ||
|
|
||
| Thread sendThread = new Thread(() -> { | ||
| try { | ||
| List<String> result = client.send("[\"REQ\",\"sub1\",{}]"); | ||
| // Without EOSE, should timeout and return empty | ||
| assertTrue(result.isEmpty(), "Should timeout and return empty list"); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| }); | ||
| sendThread.start(); | ||
|
|
||
| assertTrue(sendLatch.await(1, TimeUnit.SECONDS)); | ||
| Thread.sleep(50); | ||
|
|
||
| // Simulate EVENT message but no EOSE | ||
| client.handleTextMessage(session, new TextMessage("[\"EVENT\",\"sub1\",{\"id\":\"abc\"}]")); | ||
|
|
||
| // Don't send EOSE - should timeout | ||
| sendThread.join(1000); | ||
tcheeric marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.