Example #1
0
func TestCtxUpdateLock(t *testing.T) {
	Convey("Update lock should work fine", t, func() {
		q, _ := CreateNewQueueTestContext()
		Convey("Should fail with unknown param", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_ID, []string{PRM_ID, "ab", "TEST_PARAM"})
			So(resp.StringResponse(), ShouldContainSubstring, "TEST_PARAM")
		})
		Convey("Failure with incorrect message id", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_ID, []string{PRM_ID, "$ab", PRM_LOCK_TIMEOUT, "10000"})
			So(resp, ShouldEqual, mpqerr.ERR_ID_IS_WRONG)
		})

		Convey("Failure with empty message id", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_ID, []string{PRM_LOCK_TIMEOUT, "1"})
			So(resp, ShouldEqual, mpqerr.ERR_MSG_ID_NOT_DEFINED)
		})
		Convey("Failure with no timeout defined", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_ID, []string{PRM_ID, "1234"})
			So(resp, ShouldEqual, mpqerr.ERR_MSG_TIMEOUT_NOT_DEFINED)
		})

		Convey("Failure with no message", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_ID, []string{PRM_ID, "1234", PRM_LOCK_TIMEOUT, "100"})
			So(resp, ShouldEqual, mpqerr.ERR_MSG_NOT_FOUND)
		})

		Convey("Failure with to wrong timeout", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_ID, []string{PRM_ID, "1234", PRM_LOCK_TIMEOUT, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxLockTimeout))
		})
	})
}
Example #2
0
func TestCtxUpdateLockByReceipt(t *testing.T) {
	Convey("All call scenarios should return expected response", t, func() {
		q, _ := CreateNewQueueTestContext()
		Convey("Should return no timeout parameter error", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_RCPT, []string{PRM_RECEIPT, "1-2"})
			So(resp, ShouldEqual, mpqerr.ERR_MSG_TIMEOUT_NOT_DEFINED)
		})
		Convey("Should return invalid timeout error", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_RCPT, []string{PRM_RECEIPT, "1-2", PRM_LOCK_TIMEOUT, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxLockTimeout))
		})
		Convey("Should return unknown parameter error", func() {
			resp := q.Call(PQ_CMD_UPD_LOCK_BY_RCPT, []string{"UNKNOWN"})
			So(resp.StringResponse(), ShouldContainSubstring, "UNKNOWN")
		})
	})
}
Example #3
0
func TestCtxCheckTimeouts(t *testing.T) {
	Convey("Unlocking message should work as expected", t, func() {
		q, _ := CreateNewQueueTestContext()
		Convey("TS param needed error should be returned", func() {
			resp := q.Call(PQ_CMD_CHECK_TIMEOUTS, []string{})
			So(resp, ShouldEqual, mpqerr.ERR_TS_PARAMETER_NEEDED)
		})
		Convey("Should return unknown param error", func() {
			resp := q.Call(PQ_CMD_CHECK_TIMEOUTS, []string{"TEST_PARAM"})
			So(resp.StringResponse(), ShouldContainSubstring, "TEST_PARAM")
		})
		Convey("Should return wrong TS error", func() {
			resp := q.Call(PQ_CMD_CHECK_TIMEOUTS, []string{PRM_TIMESTAMP, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(math.MaxInt64))
		})
		Convey("Should work", func() {
			resp := q.Call(PQ_CMD_CHECK_TIMEOUTS, []string{PRM_TIMESTAMP, "1000"})
			So(resp.StringResponse(), ShouldEqual, "+DATA :0")
		})
	})
}
Example #4
0
func TestCtxPush(t *testing.T) {
	Convey("Push command should work fine", t, func() {
		q, rw := CreateNewQueueTestContext()

		Convey("Should not accept messages with underscore prefix", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "_ab", PRM_PAYLOAD, "p"})
			So(resp, ShouldEqual, mpqerr.ERR_USER_ID_IS_WRONG)
		})

		Convey("Priority should be out of range", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", PRM_PRIORITY, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(math.MaxInt64))
		})

		Convey("Message ttl should error", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", PRM_MSG_TTL, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxMessageTTL))
		})

		Convey("Delivery delay must be out of range", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", PRM_DELAY, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxDeliveryDelay))
		})
		Convey("Push with sync wait. Push should succed. Nothing special will happen.", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", PRM_DELAY, "1", PRM_SYNC_WAIT})
			VerifyOkResponse(resp)
			VerifyServiceSize(q.pq, 1)
		})
		Convey("Push async with no wait flag. Should fail with error", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", PRM_DELAY, "1", PRM_ASYNC, "asid"})
			So(resp.StringResponse(), ShouldContainSubstring, "+ASYNC asid -ERR")
		})
		Convey("Push async with wait flag. Should succed with two responses.", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", PRM_ASYNC, "asid", PRM_SYNC_WAIT})
			So(resp.StringResponse(), ShouldContainSubstring, "+A asid")
			time.Sleep(time.Millisecond * 10)
			So(rw.GetResponses()[0].StringResponse(), ShouldEqual, "+ASYNC asid +OK")
			VerifyServiceSize(q.pq, 1)
		})
		Convey("Push with unknown param.", func() {
			resp := q.Call(PQ_CMD_PUSH, []string{PRM_ID, "ab", PRM_PAYLOAD, "p", "TEST_PARAM"})
			So(resp.StringResponse(), ShouldContainSubstring, "TEST_PARAM")
		})
	})
}
Example #5
0
func TestCtxPop(t *testing.T) {
	Convey("Pop command should work", t, func() {
		q, rw := CreateNewQueueTestContext()

		Convey("Limit error should occure", func() {
			resp := q.Call(PQ_CMD_POP, []string{PRM_LIMIT, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxPopBatchSize))
		})

		Convey("Pop wait error should occure", func() {
			resp := q.Call(PQ_CMD_POP, []string{PRM_POP_WAIT, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxPopWaitTimeout))
		})

		Convey("Async error should occure", func() {
			resp := q.Call(PQ_CMD_POP, []string{PRM_ASYNC, "--++--"})
			So(resp.StringResponse(), ShouldContainSubstring, "Only [_a-z")
		})

		Convey("Unknown param error should occure", func() {
			resp := q.Call(PQ_CMD_POP, []string{"PARAM_PAM", "--++--"})
			So(resp.StringResponse(), ShouldContainSubstring, "Unknown")
		})

		Convey("Async pop should return empty list", func() {
			resp := q.Call(PQ_CMD_POP, []string{PRM_ASYNC, "a1", PRM_POP_WAIT, "1"})
			So(resp.StringResponse(), ShouldEqual, "+A a1")
			time.Sleep(time.Millisecond * 10)
			So(len(rw.GetResponses()), ShouldEqual, 1)
			So(rw.GetResponses()[0].StringResponse(), ShouldEqual, "+ASYNC a1 +MSGS *0")
		})

		Convey("Pop async run error because POP WAIT is 0", func() {
			p := []string{PRM_POP_WAIT, "0", PRM_LIMIT, "10", PRM_ASYNC, "id1"}
			resp := q.Call(PQ_CMD_POP, p)
			So(resp.StringResponse(), ShouldContainSubstring, "+ASYNC id1 -ERR")
		})

		Convey("Pop should return empty list", func() {
			p := []string{PRM_POP_WAIT, "1", PRM_LIMIT, "10"}
			resp := q.Call(PQ_CMD_POP, p)
			VerifyItems(resp, 0)
		})
	})
}
Example #6
0
func TestCtxSetParamValue(t *testing.T) {
	Convey("Set param should work well", t, func() {
		q, _ := CreateNewQueueTestContext()
		Convey("At least one parameter should be provided error", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{})
			So(resp, ShouldEqual, mpqerr.ERR_CMD_PARAM_NOT_PROVIDED)
		})
		Convey("Message TTL error", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{CPRM_MSG_TTL, "0"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxMessageTTL))
		})
		Convey("Queue Max Size", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{CPRM_MAX_MSGS_IN_QUEUE, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(math.MaxInt64))
		})
		Convey("Message delivery delay error", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{CPRM_DELIVERY_DELAY, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxDeliveryDelay))
		})
		Convey("Pop limit out of range error", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{CPRM_POP_LIMIT, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(math.MaxInt64))
		})

		Convey("Lock timeout error", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{CPRM_LOCK_TIMEOUT, "-1"})
			So(resp.StringResponse(), ShouldContainSubstring, i2a(conf.CFG_PQ.MaxLockTimeout))
		})

		Convey("Should return unknown param error", func() {
			resp := q.Call(PQ_CMD_SET_CFG, []string{"TEST_PARAM"})
			So(resp.StringResponse(), ShouldContainSubstring, "TEST_PARAM")
		})
		Convey("All parameters should be set", func() {
			params := []string{
				CPRM_DELIVERY_DELAY, "100",
				CPRM_MSG_TTL, "10000",
				CPRM_MAX_MSGS_IN_QUEUE, "100000",
			}
			VerifyOkResponse(q.Call(PQ_CMD_SET_CFG, params))
		})
	})
}