summaryrefslogtreecommitdiff
path: root/plugins/temporal/workflow/message_queue_test.go
blob: 1fcd409ffefa49c8bc25765aeb3b13032cacbb31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package workflow

import (
	"sync/atomic"
	"testing"

	"github.com/spiral/roadrunner/v2/plugins/temporal/protocol"
	"github.com/stretchr/testify/assert"
	"go.temporal.io/api/common/v1"
	"go.temporal.io/api/failure/v1"
)

func Test_MessageQueueFlushError(t *testing.T) {
	var index uint64
	mq := newMessageQueue(func() uint64 {
		return atomic.AddUint64(&index, 1)
	})

	mq.pushError(1, &failure.Failure{})
	assert.Len(t, mq.queue, 1)

	mq.flush()
	assert.Len(t, mq.queue, 0)
	assert.Equal(t, uint64(0), index)
}

func Test_MessageQueueFlushResponse(t *testing.T) {
	var index uint64
	mq := newMessageQueue(func() uint64 {
		return atomic.AddUint64(&index, 1)
	})

	mq.pushResponse(1, &common.Payloads{})
	assert.Len(t, mq.queue, 1)

	mq.flush()
	assert.Len(t, mq.queue, 0)
	assert.Equal(t, uint64(0), index)
}

func Test_MessageQueueCommandID(t *testing.T) {
	var index uint64
	mq := newMessageQueue(func() uint64 {
		return atomic.AddUint64(&index, 1)
	})

	n := mq.pushCommand(protocol.StartWorkflow{}, &common.Payloads{})
	assert.Equal(t, n, index)
	assert.Len(t, mq.queue, 1)

	mq.flush()
	assert.Len(t, mq.queue, 0)
}