Having the client unsubscribe should actually unsubscribe on the server

This commit is contained in:
Elliot Glaysher 2019-03-15 11:25:12 -07:00
parent 5da8c8bdf3
commit d954b8950d
2 changed files with 122 additions and 1 deletions

View File

@ -1197,7 +1197,27 @@
$(requests t.requests) $(requests t.requests)
:: ::
%unsubscribe %unsubscribe
!! ::
=. gall-moves
:_ gall-moves
^- move
:^ duct %pass
/channel/subscription/[channel-id]/(scot %ud request-id.i.requests)
=, i.requests
[%g %deal [our ship] `cush:gall`[app %pull ~]]
:: TODO: Check existence to prevent duplicates?
::
=. session.channel-state.state
%+ ~(jab by session.channel-state.state) channel-id
|= =channel
^+ channel
=, i.requests
%_ channel
subscriptions
(skip subscriptions.channel |=(a=[@p term ^path] =(a [ship app path])))
==
::
$(requests t.requests)
== ==
:: +on-gall-response: turns a gall response into an event :: +on-gall-response: turns a gall response into an event
:: ::

View File

@ -1014,6 +1014,107 @@
results2 results2
== ==
:: ::
++ test-channel-unsubscribe-stops-events
:: common initialization
::
=^ results1 http-server-gate (perform-init-start-channel http-server-gate *sley)
:: poke gets a success message
::
=^ results2 http-server-gate
%- http-server-take :*
http-server-gate
now=(add ~1111.1.2 ~m1)
scry=*sley
^= take-args
:* wire=/channel/poke/'0123456789abcdef'/'0' duct=~[/http-put-request]
^- (hypo sign:http-server-gate)
:- *type
[%g %unto %coup ~]
==
moves=~
==
:: subscription gets a success message
::
=^ results3 http-server-gate
%- http-server-take :*
http-server-gate
now=(add ~1111.1.2 ~m2)
scry=*sley
^= take-args
:* wire=/channel/subscription/'0123456789abcdef'/'1' duct=~[/http-put-request]
^- (hypo sign:http-server-gate)
:- *type
[%g %unto %reap ~]
==
moves=~
==
:: sending an unsubscribe sends an unsubscribe to gall
::
=^ results4 http-server-gate
%- http-server-call-with-comparator :*
http-server-gate
now=(add ~1111.1.2 ~m3)
scry=*sley
^= call-args
:* duct=~[/http-put-request] ~
%request
%.n
[%ipv4 .192.168.1.1]
%'PUT'
'/~/channel/0123456789abcdef'
['cookie' 'urbauth=0v3.q0p7t.mlkkq.cqtto.p0nvi.2ieea']~
::
:- ~
%- as-octs:mimes:html
'''
[{"action": "unsubscribe",
"id": 2,
"ship": "nul",
"app": "two",
"path": "/one/two/three"}
]
'''
==
^= comparator
|= moves=(list move:http-server-gate)
^- tang
::
?. ?=([^ ^ ^ ^ ~] moves)
[%leaf "wrong number of moves: {<(lent moves)>}"]~
::
;: weld
%+ expect-gall-deal
:* /channel/subscription/'0123456789abcdef'/'2'
[~nul ~nul] %two %pull ~
==
card.i.moves
::
%+ expect-eq
!> [~[/http-put-request] %give %response %start [200 ~] ~ %.y]
!> i.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %rest (add ~1111.1.2 ~h12)
==
!> i.t.t.moves
::
%+ expect-eq
!> :* ~[/http-put-request] %pass
/channel/timeout/'0123456789abcdef'
%b %wait :(add ~1111.1.2 ~h12 ~m3)
==
!> i.t.t.t.moves
== ==
::
;: weld
results1
results2
results3
results4
==
::
++ test-prune-events ++ test-prune-events
=/ q=(qeu [id=@ud lines=wall]) ~ =/ q=(qeu [id=@ud lines=wall]) ~
=. q (~(put to q) [0 ~]) =. q (~(put to q) [0 ~])