Skip to content

Commit e4cea13

Browse files
committed
✅ Fix test case to avoid too late adding listeners
1 parent d07d079 commit e4cea13

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

test/java/nginx/clojure/java/WebSocketTestSet4NginxJavaRingHandler.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@ public static class WSWholeTextHandler implements NginxJavaRingHandler {
191191
public Object[] invoke(Map<String, Object> request) throws IOException {
192192
NginxJavaRequest r = (NginxJavaRequest)request;
193193
NginxHttpServerChannel sc = r.hijack(true);
194-
//If we use nginx directive `auto_upgrade_ws on;`, these three lines can be omitted.
195-
if (!sc.webSocketUpgrade(true)) {
196-
return null;
197-
}
198194
sc.addListener(sc, new WholeMessageAdapter<NginxHttpServerChannel>(9*1024) {
199195
/* (non-Javadoc)
200196
* @see nginx.clojure.WholeMessageAdapter#onWholeTextMessage(java.lang.Object, java.lang.String)
@@ -204,6 +200,12 @@ public void onWholeTextMessage(NginxHttpServerChannel ch, String message) throws
204200
ch.send(message, true, false);
205201
}
206202
});
203+
204+
//If we use nginx directive `auto_upgrade_ws on;`, these three lines can be omitted.
205+
if (!sc.webSocketUpgrade(true)) {
206+
return null;
207+
}
208+
207209
return null;
208210
}
209211
}
@@ -214,10 +216,7 @@ public static class WSWholeMessageHandler implements NginxJavaRingHandler {
214216
public Object[] invoke(Map<String, Object> request) throws IOException {
215217
NginxJavaRequest r = (NginxJavaRequest)request;
216218
NginxHttpServerChannel sc = r.hijack(true);
217-
//If we use nginx directive `auto_upgrade_ws on;`, these three lines can be omitted.
218-
if (!sc.webSocketUpgrade(true)) {
219-
return null;
220-
}
219+
221220
sc.addListener(sc, new WholeMessageAdapter<NginxHttpServerChannel>(64*1024) {
222221
/* (non-Javadoc)
223222
* @see nginx.clojure.WholeMessageAdapter#onWholeTextMessage(java.lang.Object, java.lang.String)
@@ -235,6 +234,12 @@ public void onWholeBiniaryMessage(NginxHttpServerChannel ch, ByteBuffer message)
235234
ch.send(message, true, false);
236235
}
237236
});
237+
238+
//If we use nginx directive `auto_upgrade_ws on;`, these three lines can be omitted.
239+
if (!sc.webSocketUpgrade(true)) {
240+
return null;
241+
}
242+
238243
return null;
239244
}
240245
}

0 commit comments

Comments
 (0)