Skip to content

Commit

Permalink
Merge 2b4f700 into 7554818
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Dec 5, 2019
2 parents 7554818 + 2b4f700 commit fb4e2a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/rescache/eventSubscription.go
Expand Up @@ -208,7 +208,7 @@ func (e *EventSubscription) addCount() {
// in the unsubscribe queue if count reaches zero.
func (e *EventSubscription) removeCount(n int64) {
e.count -= n
if e.count == 0 {
if e.count == 0 && n != 0 {
e.cache.unsubQueue.Add(e)
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/29delete_event_test.go
Expand Up @@ -123,3 +123,35 @@ func TestDeleteEvent_FollowedByResubscribe_IsNotCached(t *testing.T) {
c.GetEvent(t).Equals(t, "test.model.custom", common.CustomEvent())
})
}

func TestDeleteEvent_OnModelQueuedForEviction_DoesNothing(t *testing.T) {
runTest(t, func(s *Session) {
c := s.Connect()
subscribeToTestModel(t, s, c)

// Unsubscribe to resource
c.Request("unsubscribe.test.model", nil).GetResponse(t)

// Send delete event
s.ResourceEvent("test.model", "delete", nil)

// Validate the delete event is sent to client
c.AssertNoEvent(t, "test.model")
})
}

func TestDeleteEvent_OnCollectionQueuedForEviction_DoesNothing(t *testing.T) {
runTest(t, func(s *Session) {
c := s.Connect()
subscribeToTestCollection(t, s, c)

// Unsubscribe to resource
c.Request("unsubscribe.test.collection", nil).GetResponse(t)

// Send delete event
s.ResourceEvent("test.collection", "delete", nil)

// Validate the delete event is sent to client
c.AssertNoEvent(t, "test.collection")
})
}
1 change: 1 addition & 0 deletions test/ws.go
Expand Up @@ -118,6 +118,7 @@ func (c *Conn) Disconnect() {
c.ws.Close()
}

// PanicOnError panics if the connection has encountered an error.
func (c *Conn) PanicOnError() {
err := c.Error()
if err != nil {
Expand Down

0 comments on commit fb4e2a0

Please sign in to comment.