Skip to content

Commit 4626618

Browse files
committed
change integration for new sdk
1 parent 54d2f59 commit 4626618

File tree

3 files changed

+45
-44
lines changed

3 files changed

+45
-44
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/agiledragon/gomonkey v2.0.2+incompatible
7-
github.com/changsongl/delay-queue-client v0.0.3
7+
github.com/changsongl/delay-queue-client v0.1.0-beta.0.20210727025911-85af22aa66a5
88
github.com/gin-gonic/gin v1.6.3
99
github.com/go-playground/validator/v10 v10.4.1 // indirect
1010
github.com/go-redis/redis/v8 v8.4.4

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+
3535
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
3636
github.com/changsongl/delay-queue-client v0.0.3 h1:Vz1b1g3WXbjQVs/FdufWKWCpM5HdEsCC3u5RyYTuJa4=
3737
github.com/changsongl/delay-queue-client v0.0.3/go.mod h1:H0o8Om/fu3QiyPLPrUop298xEUXLmlv+80wPH98v5iI=
38+
github.com/changsongl/delay-queue-client v0.1.0-beta.0.20210727025911-85af22aa66a5 h1:HhAIy5lINlXTz34orgrNoqUagt0yOoQorYNAWRT8C7M=
39+
github.com/changsongl/delay-queue-client v0.1.0-beta.0.20210727025911-85af22aa66a5/go.mod h1:H0o8Om/fu3QiyPLPrUop298xEUXLmlv+80wPH98v5iI=
3840
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
3941
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
4042
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=

test/integration/integration_test.go

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestDelayQueueAddAndRemove(t *testing.T) {
3131
for i := 0; i < Jobs; i++ {
3232
delayTime := rand.Intn(DelayTimeSeconds)
3333
id := fmt.Sprintf("test-%d", i)
34-
j, err := job.New(topic, id, job.JobDelayOption(time.Duration(delayTime)*time.Second))
34+
j, err := job.New(topic, id, job.DelayOption(time.Duration(delayTime)*time.Second))
3535
require.NoError(t, err)
3636

3737
err = AddJobRecord(key, id)
@@ -49,7 +49,7 @@ func TestDelayQueueAddAndRemove(t *testing.T) {
4949
c := consumer.New(cli, topic, consumer.WorkerNumOption(1))
5050
ch := c.Consume()
5151
for jobMsg := range ch {
52-
id := jobMsg.GetId()
52+
id := jobMsg.GetID()
5353
err := DeleteJobRecord(key, id)
5454
require.NoError(t, err)
5555

@@ -78,7 +78,7 @@ func TestDelayQueueTTR(t *testing.T) {
7878
t.Parallel()
7979

8080
topic, id := "TestDelayQueueTTR-topic", "000"
81-
j, err := job.New(topic, id, job.JobDelayOption(10*time.Second), job.JobTTROption(5*time.Second))
81+
j, err := job.New(topic, id, job.DelayOption(10*time.Second), job.TTROption(5*time.Second))
8282
require.NoError(t, err)
8383

8484
cli := client.NewClient(DelayQueueAddr)
@@ -94,7 +94,7 @@ func TestDelayQueueTTR(t *testing.T) {
9494
c := consumer.New(cli, topic, consumer.WorkerNumOption(2))
9595
ch := c.Consume()
9696
for jobMsg := range ch {
97-
jobID := jobMsg.GetId()
97+
jobID := jobMsg.GetID()
9898
t.Logf("Receive job(id: %s): %d", jobID, time.Now().Unix())
9999
if id == jobID {
100100
v := atomic.LoadInt64(&num)
@@ -109,42 +109,41 @@ func TestDelayQueueTTR(t *testing.T) {
109109
require.LessOrEqual(t, int64(4), num, "retry time should be equal")
110110
}
111111

112-
// TODO: test block
113-
// Testing ttr, consume but don't finish or delete.
114-
// Message should be consume again.
115-
//func TestDelayQueueBlockPop(t *testing.T) {
116-
// t.Parallel()
117-
//
118-
// topic, id := "TestDelayQueueBlockPop-topic", "111"
119-
// j, err := job.New(topic, id, job.JobDelayOption(0*time.Second))
120-
// require.NoError(t, err)
121-
//
122-
// blockTime := 5 * time.Second
123-
//
124-
// cli := client.NewClient(DelayQueueAddr)
125-
//
126-
// var totalTime time.Duration = 0
127-
// go func() {
128-
// // consume jobs
129-
// c := consumer.New(cli, topic, consumer.WorkerNumOption(1))
130-
// ch := c.Consume()
131-
// startTime := time.Now()
132-
// for jobMsg := range ch {
133-
// jobID := jobMsg.GetId()
134-
// t.Logf("Receive job(id: %s): %d", jobID, time.Now().Unix())
135-
// if id == jobID {
136-
// totalTime += time.Since(startTime)
137-
// }
138-
// }
139-
// }()
140-
//
141-
// time.Sleep(blockTime - 3*time.Second)
142-
// t.Logf("Add job: %d", time.Now().Unix())
143-
// err = cli.AddJob(j)
144-
// require.NoError(t, err)
145-
//
146-
// time.Sleep(blockTime)
147-
// t.Log("total-time", totalTime)
148-
// require.Greater(t, totalTime, time.Duration(0))
149-
// require.LessOrEqual(t, totalTime, blockTime)
150-
//}
112+
//Testing ttr, consume but don't finish or delete.
113+
//Message should be consume again.
114+
func TestDelayQueueBlockPop(t *testing.T) {
115+
t.Parallel()
116+
117+
topic, id := "TestDelayQueueBlockPop-topic", "111"
118+
j, err := job.New(topic, id, job.DelayOption(0*time.Second))
119+
require.NoError(t, err)
120+
121+
blockTime := 5 * time.Second
122+
123+
cli := client.NewClient(DelayQueueAddr)
124+
125+
var totalTime time.Duration = 0
126+
go func() {
127+
// consume jobs
128+
c := consumer.New(cli, topic, consumer.WorkerNumOption(1), consumer.PopTimeoutOption(blockTime))
129+
ch := c.Consume()
130+
startTime := time.Now()
131+
for jobMsg := range ch {
132+
jobID := jobMsg.GetID()
133+
t.Logf("Receive job(id: %s): %d", jobID, time.Now().Unix())
134+
if id == jobID {
135+
totalTime += time.Since(startTime)
136+
}
137+
}
138+
}()
139+
140+
time.Sleep(blockTime - 3*time.Second)
141+
t.Logf("Add job: %d", time.Now().Unix())
142+
err = cli.AddJob(j)
143+
require.NoError(t, err)
144+
145+
time.Sleep(blockTime)
146+
t.Log("total-time", totalTime)
147+
require.Greater(t, totalTime, time.Duration(0))
148+
require.LessOrEqual(t, totalTime, blockTime)
149+
}

0 commit comments

Comments
 (0)