Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webapp-lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS-214
ul2024
webapp-lib
Commits
13687b54
Commit
13687b54
authored
4 months ago
by
Clément Pit-Claudel
Browse files
Options
Downloads
Patches
Plain Diff
tests: Check that server accepts large number of connected clients
parent
7915271a
No related branches found
No related tags found
1 merge request
!40
Properly handle sudden websocket disconnections
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jvm/src/test/scala/cs214/webapp/AppSuite.scala
+45
-0
45 additions, 0 deletions
jvm/src/test/scala/cs214/webapp/AppSuite.scala
with
45 additions
and
0 deletions
jvm/src/test/scala/cs214/webapp/AppSuite.scala
+
45
−
0
View file @
13687b54
...
...
@@ -169,3 +169,48 @@ class WebSocketSuite extends PingPongSuite:
ws
.
sendText
(
app
.
wire
.
eventFormat
.
encode
(
"b"
).
toString
)
val
r0b
=
decodeActions
(
ws
.
receiveText
())
assertEquals
(
r0b
,
Seq
(
Action
.
Render
(
"b"
)))
test
(
"ws: Webserver survives many connections to a single app"
)
:
withServer:
server
?=>
def
userId
(
n:
Int
)
=
f
"p$n"
def
withJavaWss
[
Lst
<:
JWebSocket.Listener
]
(
instanceId
:
String
,
nUsers
:
Int
,
listener
:
String
=>
Lst
)
(
body
:
Seq
[(
JWebSocket
,
Lst
)]
=>
Unit
)
=
def
loop
(
i
:
Int
,
wss
:
Seq
[(
JWebSocket
,
Lst
)])
:
Unit
=
if
i
>=
nUsers
then
body
(
wss
)
wss
.
foreach
:
(
ws
,
lst
)
=>
ws
.
sendClose
(
1000
,
"bye"
)
ws
.
abort
()
else
val
uId
=
userId
(
i
)
val
lst
=
listener
(
uId
)
val
ws
=
withJavaWs
(
instanceId
,
uId
,
lst
)(
ws
=>
ws
)
loop
(
i
+
1
,
(
ws
,
lst
)
+:
wss
)
loop
(
0
,
Seq
())
val
nUsers
=
1000
val
inst
=
createInstance
((
0
to
nUsers
).
map
(
userId
))
class
QueuedListener
extends
JWebSocket
.
Listener
:
var
partials:
String
=
""
val
queue
=
java
.
util
.
concurrent
.
LinkedTransferQueue
[
String
]()
def
receiveText
()
=
queue
.
take
()
override
def
onText
(
webSocket
:
JWebSocket
,
data
:
CharSequence
,
last
:
Boolean
)
:
java.util.concurrent.CompletionStage
[
?
]
=
webSocket
.
synchronized
:
partials
+=
data.toString
if
last
then
queue
.
add
(
partials
)
partials
=
""
super
.
onText
(
webSocket
,
data
,
last
)
withJavaWss
(
inst
.
instanceId
,
nUsers
,
_
=>
QueuedListener
())
:
wss
=>
wss
.
head
.
_1
.
sendText
(
app
.
wire
.
eventFormat
.
encode
(
"a"
).
toString
,
true
)
val
rng
=
scala
.
util
.
Random
(
12
)
rng
.
shuffle
(
wss
).
foreach
:
(
ws
,
lst
)
=>
assertEquals
(
decodeActions
(
lst
.
receiveText
()),
Seq
(
Action
.
Render
(
"hello"
)))
assertEquals
(
decodeActions
(
lst
.
receiveText
()),
Seq
(
Action
.
Render
(
"a"
)))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment