Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support suspend list #315

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,13 @@
"items": {
"type": "int"
}
},
"Suspended": {
"description": "Suspended list of suspended object handles or nil",
"type": "slice",
"items": {
"type": "int"
}
}
}
},
Expand Down
5 changes: 3 additions & 2 deletions json_rpc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ type (
}

rpcStatusInfo struct {
Change []int `json:"change"`
Close []int `json:"close"`
Change []int `json:"change"`
Close []int `json:"close"`
Suspend []int `json:"suspend"`
}

// socketOutput represents a request message sent to Qlik Associative Engine
Expand Down
4 changes: 3 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type (
Changed []int
// Closed list of closed object handles or nil
Closed []int
// Suspended list of suspended object handles or nil
Suspended []int
}
)

Expand Down Expand Up @@ -142,7 +144,7 @@ func (q *session) handleResponse(message []byte, receiveTimestamp time.Time) {
q.emitSessionMessage(rpcResponse.Method, rpcResponse.Params)
} else {
pendingCall := q.removePendingCall(rpcResponse.ID)
q.emitChangeLists(rpcResponse.Change, rpcResponse.Close, pendingCall == nil) // Emit this before marking the pending call as done to make sure it is there when the pending call returns
q.emitChangeLists(rpcResponse.Change, rpcResponse.Close, rpcResponse.Suspend, pendingCall == nil) // Emit this before marking the pending call as done to make sure it is there when the pending call returns
if pendingCall != nil {
pendingCall.Response = rpcResponse
pendingCall.receiveTimestamp = receiveTimestamp
Expand Down
4 changes: 2 additions & 2 deletions session_change_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ type (
}
)

func (e *sessionChangeLists) emitChangeLists(changed []int, closed []int, pushed bool) {
func (e *sessionChangeLists) emitChangeLists(changed, closed, suspended []int, pushed bool) {
if len(changed) > 0 || len(closed) > 0 {
e.mutex.Lock()
defer e.mutex.Unlock()

for channelEntry := range e.channels {
if pushed || !channelEntry.pushedOnly {
channelEntry.channel <- ChangeLists{Changed: changed, Closed: closed}
channelEntry.channel <- ChangeLists{Changed: changed, Closed: closed, Suspended: suspended}
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions session_change_lists_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package enigma

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSessionChangeLists(t *testing.T) {
Expand All @@ -12,20 +13,23 @@ func TestSessionChangeLists(t *testing.T) {
pushedChangeListsChannel := s.ChangeListsChannel(true)

// Emit two lists
s.emitChangeLists([]int{1, 2}, []int{3, 4}, true)
s.emitChangeLists([]int{5, 6}, []int{7, 8}, false)
s.emitChangeLists([]int{1, 2}, []int{3, 4}, []int{9, 10}, true)
s.emitChangeLists([]int{5, 6}, []int{7, 8}, []int{11, 12}, false)

// Check that the lists appear as expecgted
// Check that the lists appear as expected
allData1 := <-allChangeListsChannel
allData2 := <-allChangeListsChannel
assert.Equal(t, 1, allData1.Changed[0])
assert.Equal(t, 3, allData1.Closed[0])
assert.Equal(t, 9, allData1.Suspended[0])
assert.Equal(t, 5, allData2.Changed[0])
assert.Equal(t, 7, allData2.Closed[0])
assert.Equal(t, 11, allData2.Suspended[0])

pushedData1 := <-pushedChangeListsChannel
assert.Equal(t, 1, pushedData1.Changed[0])
assert.Equal(t, 3, pushedData1.Closed[0])
assert.Equal(t, 9, pushedData1.Suspended[0])

// Check that the second non-pushed list doesn't appear
var nothingInChangePushedChangeList bool
Expand Down