Skip to content

Commit

Permalink
GH-98: Testing that unnecessary access is not sent when calling Ensur…
Browse files Browse the repository at this point in the history
…eAccess.
  • Loading branch information
jirenius committed Jul 31, 2019
1 parent d2da096 commit 6036fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 2 additions & 3 deletions server/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ type Subscription struct {
accessCalled bool

// Protected by conn
direct int // Number of direct subscriptions
indirect int // Number of indirect subscriptions
indirectReaccess int // Number of indirect subscriptions currently under reaccess
direct int // Number of direct subscriptions
indirect int // Number of indirect subscriptions
}

type reference struct {
Expand Down
22 changes: 22 additions & 0 deletions test/10reaccess_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,25 @@ func TestUnsubscribingParentTriggersAccessCall(t *testing.T) {
c.GetEvent(t).Equals(t, "test.model.custom", event)
})
}

// Test that unsubscribing a parent resource to a child that was subscribed prior
// to the parent resource will not trigger a new access call on the child.
func TestUnsubscribingParentToPresubscribedChildDoesNotTriggerAccessCall(t *testing.T) {
runTest(t, func(s *Session) {
event := json.RawMessage(`{"foo":"bar"}`)

c := s.Connect()

// Get child model first
subscribeToTestModel(t, s, c)
// Get parent model afterwards
subscribeToTestModelParent(t, s, c, true)

// Call unsubscribe on parent
c.Request("unsubscribe.test.model.parent", nil).GetResponse(t)

// Send event on child model and validate client event
s.ResourceEvent("test.model", "custom", event)
c.GetEvent(t).Equals(t, "test.model.custom", event)
})
}

0 comments on commit 6036fe6

Please sign in to comment.