Skip to content

Commit

Permalink
Tweak lua script for checking loops, add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Aug 16, 2019
1 parent 80e7e1c commit a5f52de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 2 additions & 4 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,11 @@ var luaMsgLoop = redis.NewScript(3, `-- KEYS: [key, contact_id, text]
-- try to look up in window
local record = redis.call("hget", key, contact_id)
if record then
local record_count = string.sub(record, 1, 2)
local record_count = tonumber(string.sub(record, 1, 2))
local record_text = string.sub(record, 4, -1)
if record_text == text then
if count < 99 then
count = tonumber(record_count) + 1
end
count = math.min(record_count + 1, 99)
else
count = 1
end
Expand Down
7 changes: 7 additions & 0 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,13 @@ func (ts *BackendTestSuite) TestLoop() {
loop, err = ts.b.IsMsgLoop(ctx, dbMsg)
ts.NoError(err)
ts.True(loop)

// make sure this keeps working even in hundreds of loops
for i := 0; i < 100; i++ {
loop, err = ts.b.IsMsgLoop(ctx, dbMsg)
ts.NoError(err)
ts.True(loop)
}
}

func (ts *BackendTestSuite) TestStatus() {
Expand Down

0 comments on commit a5f52de

Please sign in to comment.