本文整理汇总了Golang中github.com/customerio/gospec.Context.Specify方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Specify方法的具体用法?Golang Context.Specify怎么用?Golang Context.Specify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/customerio/gospec.Context
的用法示例。
在下文中一共展示了Context.Specify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ScheduledSpec
func ScheduledSpec(c gospec.Context) {
scheduled := newScheduled(RETRY_KEY)
was := Config.namespace
Config.namespace = "prod:"
c.Specify("empties retry queues up to the current time", func() {
conn := Config.Pool.Get()
defer conn.Close()
now := time.Now().Unix()
message1, _ := NewMsg("{\"queue\":\"default\",\"foo\":\"bar1\"}")
message2, _ := NewMsg("{\"queue\":\"myqueue\",\"foo\":\"bar2\"}")
message3, _ := NewMsg("{\"queue\":\"default\",\"foo\":\"bar3\"}")
conn.Do("zadd", "prod:"+RETRY_KEY, now-60, message1.ToJson())
conn.Do("zadd", "prod:"+RETRY_KEY, now-10, message2.ToJson())
conn.Do("zadd", "prod:"+RETRY_KEY, now+60, message3.ToJson())
scheduled.poll(false)
defaultCount, _ := redis.Int(conn.Do("llen", "prod:queue:default"))
myqueueCount, _ := redis.Int(conn.Do("llen", "prod:queue:myqueue"))
pending, _ := redis.Int(conn.Do("zcard", "prod:"+RETRY_KEY))
c.Expect(defaultCount, Equals, 1)
c.Expect(myqueueCount, Equals, 1)
c.Expect(pending, Equals, 1)
})
Config.namespace = was
}
示例2: WorkersSpec
func WorkersSpec(c gospec.Context) {
c.Specify("Workers", func() {
c.Specify("allows running in tests", func() {
called = make(chan bool)
Process("myqueue", myJob, 10)
Start()
Enqueue("myqueue", "Add", []int{1, 2})
<-called
Quit()
})
})
}
示例3: ChanneledConnectionSpec
func ChanneledConnectionSpec(c gospec.Context) {
config := NewConfig("localhost:6379", "15", 2)
config.AddQueue("myqueue", "typea")
config.AddQueue("myqueue2", "typeb")
conn := NewChanneledConnection(config, func(message *Msg) string {
channel, _ := message.Get("type").String()
return fmt.Sprint("channel:type", channel, ":channel")
})
c.Specify("Deliver", func() {
c.Specify("only queues up message for matching queues", func() {
r := config.Pool.Get()
defer r.Close()
count, _ := redis.Int(r.Do("llen", "fairway:myqueue:default"))
c.Expect(count, Equals, 0)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue2:default"))
c.Expect(count, Equals, 0)
msg, _ := NewMsg(map[string]string{"type": "a"})
conn.Deliver(msg)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue:default"))
c.Expect(count, Equals, 1)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue2:default"))
c.Expect(count, Equals, 0)
})
})
c.Specify("DeliverBytes", func() {
c.Specify("only queues up message for matching queues", func() {
r := config.Pool.Get()
defer r.Close()
count, _ := redis.Int(r.Do("llen", "fairway:myqueue:default"))
c.Expect(count, Equals, 0)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue2:default"))
c.Expect(count, Equals, 0)
msg, _ := NewMsg(map[string]string{"type": "a"})
conn.DeliverBytes("channel:typea:channel", "default", []byte(msg.json()))
count, _ = redis.Int(r.Do("llen", "fairway:myqueue:default"))
c.Expect(count, Equals, 1)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue2:default"))
c.Expect(count, Equals, 0)
})
})
}
示例4: ConfigSpec
func ConfigSpec(c gospec.Context) {
var recoverOnPanic = func(f func()) (err interface{}) {
defer func() {
if cause := recover(); cause != nil {
err = cause
}
}()
f()
return
}
c.Specify("sets redis pool size which defaults to 1", func() {
c.Expect(Config.pool.MaxIdle, Equals, 1)
Configure(map[string]string{
"server": "localhost:6379",
"process": "1",
"pool": "20",
})
c.Expect(Config.pool.MaxIdle, Equals, 20)
})
c.Specify("can specify custom process", func() {
c.Expect(Config.processId, Equals, "1")
Configure(map[string]string{
"server": "localhost:6379",
"process": "2",
})
c.Expect(Config.processId, Equals, "2")
})
c.Specify("requires a server parameter", func() {
err := recoverOnPanic(func() {
Configure(map[string]string{"process": "2"})
})
c.Expect(err, Equals, "Configure requires a 'server' option, which identifies a Redis instance")
})
c.Specify("requires a process parameter", func() {
err := recoverOnPanic(func() {
Configure(map[string]string{"server": "localhost:6379"})
})
c.Expect(err, Equals, "Configure requires a 'process' option, which uniquely identifies this instance")
})
}
示例5: MiddlewareStatsSpec
func MiddlewareStatsSpec(c gospec.Context) {
var job = (func(args *Args) {
// noop
})
layout := "2006-01-02"
manager := newManager("myqueue", job, 1)
worker := newWorker(manager)
message, _ := NewMsg("{\"jid\":\"2\",\"retry\":true}")
c.Specify("increments processed stats", func() {
conn := Config.Pool.Get()
defer conn.Close()
count, _ := redis.Int(conn.Do("get", "stat:processed"))
dayCount, _ := redis.Int(conn.Do("get", "stat:processed:"+time.Now().UTC().Format(layout)))
c.Expect(count, Equals, 0)
c.Expect(dayCount, Equals, 0)
worker.process(message)
count, _ = redis.Int(conn.Do("get", "stat:processed"))
dayCount, _ = redis.Int(conn.Do("get", "stat:processed:"+time.Now().UTC().Format(layout)))
c.Expect(count, Equals, 1)
c.Expect(dayCount, Equals, 1)
})
c.Specify("failed job", func() {
var job = (func(args *Args) {
panic("AHHHH")
})
manager := newManager("myqueue", job, 1)
worker := newWorker(manager)
c.Specify("increments failed stats", func() {
conn := Config.Pool.Get()
defer conn.Close()
count, _ := redis.Int(conn.Do("get", "stat:failed"))
dayCount, _ := redis.Int(conn.Do("get", "stat:failed:"+time.Now().UTC().Format(layout)))
c.Expect(count, Equals, 0)
c.Expect(dayCount, Equals, 0)
worker.process(message)
count, _ = redis.Int(conn.Do("get", "stat:failed"))
dayCount, _ = redis.Int(conn.Do("get", "stat:failed:"+time.Now().UTC().Format(layout)))
c.Expect(count, Equals, 1)
c.Expect(dayCount, Equals, 1)
})
})
}
示例6: EnqueueSpec
func EnqueueSpec(c gospec.Context) {
was := Config.namespace
Config.namespace = "prod:"
c.Specify("Enqueue", func() {
conn := Config.Pool.Get()
defer conn.Close()
c.Specify("makes the queue available", func() {
Enqueue("enqueue1", "Add", []int{1, 2})
found, _ := redis.Bool(conn.Do("sismember", "prod:queues", "enqueue1"))
c.Expect(found, IsTrue)
})
c.Specify("adds a job to the queue", func() {
nb, _ := redis.Int(conn.Do("llen", "prod:queue:enqueue2"))
c.Expect(nb, Equals, 0)
Enqueue("enqueue2", "Add", []int{1, 2})
nb, _ = redis.Int(conn.Do("llen", "prod:queue:enqueue2"))
c.Expect(nb, Equals, 1)
})
c.Specify("saves the arguments", func() {
Enqueue("enqueue3", "Compare", []string{"foo", "bar"})
bytes, _ := redis.Bytes(conn.Do("lpop", "prod:queue:enqueue3"))
var result map[string]interface{}
json.Unmarshal(bytes, &result)
c.Expect(result["class"], Equals, "Compare")
args := result["args"].([]interface{})
c.Expect(len(args), Equals, 2)
c.Expect(args[0], Equals, "foo")
c.Expect(args[1], Equals, "bar")
})
})
Config.namespace = was
}
示例7: WorkerSpec
func WorkerSpec(c gospec.Context) {
var processed = make(chan *Args)
var testJob = (func(message *Msg) {
processed <- message.Args()
})
manager := newManager("myqueue", testJob, 1)
c.Specify("newWorker", func() {
c.Specify("it returns an instance of worker with connection to manager", func() {
worker := newWorker(manager)
c.Expect(worker.manager, Equals, manager)
})
})
c.Specify("work", func() {
worker := newWorker(manager)
messages := make(chan *Msg)
message, _ := NewMsg("{\"jid\":\"2309823\",\"args\":[\"foo\",\"bar\"]}")
c.Specify("calls job with message args", func() {
go worker.work(messages)
messages <- message
args, _ := (<-processed).Array()
<-manager.confirm
c.Expect(len(args), Equals, 2)
c.Expect(args[0], Equals, "foo")
c.Expect(args[1], Equals, "bar")
worker.quit()
})
c.Specify("confirms job completed", func() {
go worker.work(messages)
messages <- message
<-processed
c.Expect(confirm(manager), Equals, message)
worker.quit()
})
c.Specify("runs defined middleware and confirms", func() {
Middleware.Append(&testMiddleware{})
go worker.work(messages)
messages <- message
<-processed
c.Expect(confirm(manager), Equals, message)
c.Expect(testMiddlewareCalled, IsTrue)
worker.quit()
Middleware = NewMiddleware(
&MiddlewareLogging{},
&MiddlewareRetry{},
&MiddlewareStats{},
)
})
c.Specify("doesn't confirm if middleware cancels acknowledgement", func() {
Middleware.Append(&failMiddleware{})
go worker.work(messages)
messages <- message
<-processed
c.Expect(confirm(manager), IsNil)
c.Expect(failMiddlewareCalled, IsTrue)
worker.quit()
Middleware = NewMiddleware(
&MiddlewareLogging{},
&MiddlewareRetry{},
&MiddlewareStats{},
)
})
c.Specify("recovers and confirms if job panics", func() {
var panicJob = (func(message *Msg) {
panic("AHHHHHHHHH")
})
manager := newManager("myqueue", panicJob, 1)
worker := newWorker(manager)
go worker.work(messages)
messages <- message
c.Expect(confirm(manager), Equals, message)
worker.quit()
})
})
//.........这里部分代码省略.........
示例8: ManagerSpec
func ManagerSpec(c gospec.Context) {
processed := make(chan *Args)
testJob := (func(args *Args) {
processed <- args
})
c.Specify("newManager", func() {
c.Specify("sets queue with namespace", func() {
manager := newManager("myqueue", testJob, 10)
c.Expect(manager.queue, Equals, "queue:myqueue")
})
c.Specify("sets job function", func() {
manager := newManager("myqueue", testJob, 10)
c.Expect(fmt.Sprint(manager.job), Equals, fmt.Sprint(testJob))
})
c.Specify("sets worker concurrency", func() {
manager := newManager("myqueue", testJob, 10)
c.Expect(manager.concurrency, Equals, 10)
})
})
c.Specify("manage", func() {
conn := Config.pool.Get()
defer conn.Close()
message, _ := NewMsg("{\"foo\":\"bar\",\"args\":[\"foo\",\"bar\"]}")
message2, _ := NewMsg("{\"foo\":\"bar2\",\"args\":[\"foo\",\"bar2\"]}")
c.Specify("coordinates processing of queue messages", func() {
manager := newManager("manager1", testJob, 10)
conn.Do("lpush", "queue:manager1", message.ToJson())
conn.Do("lpush", "queue:manager1", message2.ToJson())
manager.start()
c.Expect(<-processed, Equals, message.Args())
c.Expect(<-processed, Equals, message2.Args())
manager.quit()
len, _ := redis.Int(conn.Do("llen", "queue:manager1"))
c.Expect(len, Equals, 0)
})
c.Specify("prepare stops fetching new messages from queue", func() {
manager := newManager("manager2", testJob, 10)
manager.start()
manager.prepare()
conn.Do("lpush", "queue:manager2", message)
conn.Do("lpush", "queue:manager2", message2)
manager.quit()
len, _ := redis.Int(conn.Do("llen", "queue:manager2"))
c.Expect(len, Equals, 2)
})
})
}
示例9: ConnectionSpec
func ConnectionSpec(c gospec.Context) {
config := NewConfig("localhost:6379", "15", 2)
config.AddQueue("myqueue", ".*")
conn := NewConnection(config)
c.Specify("NewConnection", func() {
c.Specify("registers any queues defined in configuration", func() {
c.Expect(len(conn.Queues()), Equals, 1)
config.AddQueue("myqueue2", ".*")
conn.RegisterQueues()
c.Expect(len(conn.Queues()), Equals, 2)
})
c.Specify("stores registered queues in redis", func() {
r := config.Pool.Get()
defer r.Close()
values, _ := redis.Strings(r.Do("hgetall", "fairway:registered_queues"))
expected := []string{"myqueue", ".*"}
for i, str := range values {
c.Expect(str, Equals, expected[i])
}
})
})
c.Specify("Queues", func() {
c.Specify("returns a Queue for every currently registered queue", func() {
c.Expect(*conn.Queues()[0], Equals, *NewQueue(conn, "myqueue"))
})
})
c.Specify("Deliver", func() {
c.Specify("adds message to the facet for the queue", func() {
r := config.Pool.Get()
defer r.Close()
count, _ := redis.Int(r.Do("llen", "fairway:myqueue:default"))
c.Expect(count, Equals, 0)
msg, _ := NewMsg(map[string]string{"name": "mymessage"})
conn.Deliver(msg)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue:default"))
c.Expect(count, Equals, 1)
value, _ := redis.String(r.Do("lindex", "fairway:myqueue:default", 0))
c.Expect(value, Equals, msg.json())
})
c.Specify("adds facets to the list of active facets", func() {
r := config.Pool.Get()
defer r.Close()
facets, _ := redis.Strings(r.Do("smembers", "fairway:myqueue:active_facets"))
c.Expect(len(facets), Equals, 0)
msg, _ := NewMsg(map[string]string{})
conn.Deliver(msg)
facets, _ = redis.Strings(r.Do("smembers", "fairway:myqueue:active_facets"))
c.Expect(len(facets), Equals, 1)
c.Expect(facets[0], Equals, "default")
})
c.Specify("pushes facet onto the facet queue", func() {
r := config.Pool.Get()
defer r.Close()
count, _ := redis.Int(r.Do("llen", "fairway:myqueue:facet_queue"))
c.Expect(count, Equals, 0)
msg, _ := NewMsg(map[string]string{})
conn.Deliver(msg)
count, _ = redis.Int(r.Do("llen", "fairway:myqueue:facet_queue"))
c.Expect(count, Equals, 1)
value, _ := redis.String(r.Do("lindex", "fairway:myqueue:facet_queue", 0))
c.Expect(value, Equals, "default")
})
c.Specify("doesn't push facet if already active", func() {
r := config.Pool.Get()
defer r.Close()
r.Do("sadd", "fairway:myqueue:active_facets", "default")
r.Do("hset", "fairway:myqueue:facet_pool", "default", "1")
msg, _ := NewMsg(map[string]string{})
conn.Deliver(msg)
count, _ := redis.Int(r.Do("llen", "fairway:myqueue:facet_queue"))
c.Expect(count, Equals, 0)
})
//.........这里部分代码省略.........
示例10: MsgSpec
func MsgSpec(c gospec.Context) {
c.Specify("NewMsg", func() {
c.Specify("returns a new message with body as the content", func() {
msg, _ := NewMsg(map[string]string{"hello": "world"})
c.Expect(msg.json(), Equals, "{\"hello\":\"world\"}")
})
c.Specify("returns err if couldn't convert object", func() {
msg, err := NewMsg(func() {})
c.Expect(msg, IsNil)
c.Expect(err, Not(IsNil))
})
})
c.Specify("NewMsgFromString", func() {
c.Specify("returns a new message with string as the content", func() {
msg, _ := NewMsgFromString("{\"hello\":\"world\"}")
c.Expect(msg.json(), Equals, "{\"hello\":\"world\"}")
})
c.Specify("returns err if couldn't convert string", func() {
msg, err := NewMsgFromString("not json")
c.Expect(msg, IsNil)
c.Expect(err, Not(IsNil))
})
})
}
示例11: MsgSpec
func MsgSpec(c gospec.Context) {
c.Specify("NewMsg", func() {
c.Specify("unmarshals json", func() {
msg, _ := NewMsg("{\"hello\":\"world\",\"foo\":3}")
hello, _ := msg.Get("hello").String()
foo, _ := msg.Get("foo").Int()
c.Expect(hello, Equals, "world")
c.Expect(foo, Equals, 3)
})
c.Specify("returns an error if invalid json", func() {
msg, err := NewMsg("{\"hello:\"world\",\"foo\":3}")
c.Expect(msg, IsNil)
c.Expect(err, Not(IsNil))
})
})
c.Specify("Args", func() {
c.Specify("returns args key", func() {
msg, _ := NewMsg("{\"hello\":\"world\",\"args\":[\"foo\",\"bar\"]}")
c.Expect(msg.Args().ToJson(), Equals, "[\"foo\",\"bar\"]")
})
c.Specify("returns empty array if args key doesn't exist", func() {
msg, _ := NewMsg("{\"hello\":\"world\"}")
c.Expect(msg.Args().ToJson(), Equals, "[]")
})
})
}
示例12: FetchSpec
func FetchSpec(c gospec.Context) {
c.Specify("Config.Fetch", func() {
c.Specify("it returns an instance of fetch with queue", func() {
fetch := buildFetch("fetchQueue1")
c.Expect(fetch.Queue(), Equals, "queue:fetchQueue1")
fetch.Close()
})
})
c.Specify("Fetch", func() {
message, _ := NewMsg("{\"foo\":\"bar\"}")
c.Specify("it puts messages from the queues on the messages channel", func() {
fetch := buildFetch("fetchQueue2")
conn := Config.Pool.Get()
defer conn.Close()
conn.Do("lpush", "queue:fetchQueue2", message.ToJson())
message := <-fetch.Messages()
c.Expect(message, Equals, message)
len, _ := redis.Int(conn.Do("llen", "queue:fetchQueue2"))
c.Expect(len, Equals, 0)
fetch.Close()
})
c.Specify("places in progress messages on private queue", func() {
fetch := buildFetch("fetchQueue3")
conn := Config.Pool.Get()
defer conn.Close()
conn.Do("lpush", "queue:fetchQueue3", message.ToJson())
<-fetch.Messages()
len, _ := redis.Int(conn.Do("llen", "queue:fetchQueue3:1:inprogress"))
c.Expect(len, Equals, 1)
messages, _ := redis.Strings(conn.Do("lrange", "queue:fetchQueue3:1:inprogress", 0, -1))
c.Expect(messages[0], Equals, message.ToJson())
fetch.Close()
})
c.Specify("removes in progress message when acknowledged", func() {
fetch := buildFetch("fetchQueue4")
conn := Config.Pool.Get()
defer conn.Close()
conn.Do("lpush", "queue:fetchQueue4", message.ToJson())
<-fetch.Messages()
fetch.Acknowledge(message)
len, _ := redis.Int(conn.Do("llen", "queue:fetchQueue4:1:inprogress"))
c.Expect(len, Equals, 0)
fetch.Close()
})
c.Specify("removes in progress message when serialized differently", func() {
json := "{\"foo\":\"bar\",\"args\":[]}"
message, _ := NewMsg(json)
c.Expect(json, Not(Equals), message.ToJson())
fetch := buildFetch("fetchQueue5")
conn := Config.Pool.Get()
defer conn.Close()
conn.Do("lpush", "queue:fetchQueue5", json)
<-fetch.Messages()
fetch.Acknowledge(message)
len, _ := redis.Int(conn.Do("llen", "queue:fetchQueue5:1:inprogress"))
c.Expect(len, Equals, 0)
fetch.Close()
})
c.Specify("refires any messages left in progress from prior instance", func() {
message2, _ := NewMsg("{\"foo\":\"bar2\"}")
message3, _ := NewMsg("{\"foo\":\"bar3\"}")
conn := Config.Pool.Get()
defer conn.Close()
conn.Do("lpush", "queue:fetchQueue6:1:inprogress", message.ToJson())
conn.Do("lpush", "queue:fetchQueue6:1:inprogress", message2.ToJson())
conn.Do("lpush", "queue:fetchQueue6", message3.ToJson())
//.........这里部分代码省略.........
示例13: ConfigSpec
func ConfigSpec(c gospec.Context) {
config := NewConfig("localhost:6379", "15", 10)
c.Specify("NewConfig", func() {
c.Specify("namespace is fairway", func() {
c.Expect(config.Namespace, Equals, "fairway")
})
c.Specify("sets the facet to always return 'default'", func() {
msg, _ := NewMsg(make([]string, 0))
c.Expect(config.Facet(msg), Equals, "default")
})
c.Specify("doesn't have any defined queues", func() {
c.Expect(len(config.queues), Equals, 0)
})
})
c.Specify("sets redis pool size", func() {
c.Expect(config.Pool.MaxIdle, Equals, 10)
c.Expect(config.Pool.MaxActive, Equals, 0)
config = NewConfig("localhost:6379", "15", 20)
c.Expect(config.Pool.MaxIdle, Equals, 20)
c.Expect(config.Pool.MaxActive, Equals, 0)
})
c.Specify("can specify custom namespace", func() {
config.Namespace = "mynamespace"
c.Expect(config.Namespace, Equals, "mynamespace")
})
c.Specify("can specify custom facet", func() {
config.Facet = func(message *Msg) string {
return "myfacet"
}
msg, _ := NewMsg(make([]string, 0))
c.Expect(config.Facet(msg), Equals, "myfacet")
})
c.Specify("can define a queue", func() {
config.AddQueue("myqueue", "default")
c.Expect(len(config.queues), Equals, 1)
c.Expect(*config.queues[0], Equals, QueueDefinition{"myqueue", "default"})
})
}
示例14: WorkerSpec
func WorkerSpec(c gospec.Context) {
var processed = make(chan *Args)
middlewareCalled = false
var testJob = (func(args *Args) {
processed <- args
})
manager := newManager("myqueue", testJob, 1)
c.Specify("newWorker", func() {
c.Specify("it returns an instance of worker with connection to manager", func() {
worker := newWorker(manager)
c.Expect(worker.manager, Equals, manager)
})
})
c.Specify("work", func() {
worker := newWorker(manager)
messages := make(chan *Msg)
message, _ := NewMsg("{\"jid\":\"2309823\",\"args\":[\"foo\",\"bar\"]}")
c.Specify("calls job with message args", func() {
go worker.work(messages)
messages <- message
args, _ := (<-processed).Array()
<-manager.confirm
c.Expect(len(args), Equals, 2)
c.Expect(args[0], Equals, "foo")
c.Expect(args[1], Equals, "bar")
worker.quit()
})
c.Specify("confirms job completed", func() {
go worker.work(messages)
messages <- message
<-processed
c.Expect(<-manager.confirm, Equals, message)
worker.quit()
})
c.Specify("runs defined middleware", func() {
Middleware.Append(&testMiddleware{})
go worker.work(messages)
messages <- message
<-processed
<-manager.confirm
c.Expect(middlewareCalled, IsTrue)
worker.quit()
})
c.Specify("recovers and confirms if job panics", func() {
var panicJob = (func(args *Args) {
panic("AHHHHHHHHH")
})
manager := newManager("myqueue", panicJob, 1)
worker := newWorker(manager)
go worker.work(messages)
messages <- message
c.Expect(<-manager.confirm, Equals, message)
worker.quit()
})
})
}
示例15: MiddlewareRetrySpec
func MiddlewareRetrySpec(c gospec.Context) {
var panicingJob = (func(args *Args) {
panic("AHHHH")
})
var wares = newMiddleware(
&MiddlewareRetry{},
)
layout := "2006-01-02 15:04:05 MST"
manager := newManager("myqueue", panicingJob, 1)
worker := newWorker(manager)
c.Specify("puts messages in retry queue when they fail", func() {
message, _ := NewMsg("{\"jid\":\"2\",\"retry\":true}")
wares.call("myqueue", message, func() {
worker.process(message)
})
conn := Config.Pool.Get()
defer conn.Close()
retries, _ := redis.Strings(conn.Do("zrange", RETRY_KEY, 0, 1))
c.Expect(retries[0], Equals, message.ToJson())
})
c.Specify("allows disabling retries", func() {
message, _ := NewMsg("{\"jid\":\"2\",\"retry\":false}")
wares.call("myqueue", message, func() {
worker.process(message)
})
conn := Config.Pool.Get()
defer conn.Close()
count, _ := redis.Int(conn.Do("zcard", RETRY_KEY))
c.Expect(count, Equals, 0)
})
c.Specify("doesn't retry by default", func() {
message, _ := NewMsg("{\"jid\":\"2\"}")
wares.call("myqueue", message, func() {
worker.process(message)
})
conn := Config.Pool.Get()
defer conn.Close()
count, _ := redis.Int(conn.Do("zcard", RETRY_KEY))
c.Expect(count, Equals, 0)
})
c.Specify("allows numeric retries", func() {
message, _ := NewMsg("{\"jid\":\"2\",\"retry\":5}")
wares.call("myqueue", message, func() {
worker.process(message)
})
conn := Config.Pool.Get()
defer conn.Close()
retries, _ := redis.Strings(conn.Do("zrange", RETRY_KEY, 0, 1))
c.Expect(retries[0], Equals, message.ToJson())
})
c.Specify("handles new failed message", func() {
message, _ := NewMsg("{\"jid\":\"2\",\"retry\":true}")
wares.call("myqueue", message, func() {
worker.process(message)
})
conn := Config.Pool.Get()
defer conn.Close()
retries, _ := redis.Strings(conn.Do("zrange", RETRY_KEY, 0, 1))
message, _ = NewMsg(retries[0])
queue, _ := message.Get("queue").String()
error_message, _ := message.Get("error_message").String()
error_class, _ := message.Get("error_class").String()
retry_count, _ := message.Get("retry_count").Int()
error_backtrace, _ := message.Get("error_backtrace").String()
failed_at, _ := message.Get("failed_at").String()
c.Expect(queue, Equals, "myqueue")
c.Expect(error_message, Equals, "AHHHH")
c.Expect(error_class, Equals, "")
c.Expect(retry_count, Equals, 0)
c.Expect(error_backtrace, Equals, "")
c.Expect(failed_at, Equals, time.Now().UTC().Format(layout))
})
c.Specify("handles recurring failed message", func() {
message, _ := NewMsg("{\"jid\":\"2\",\"retry\":true,\"queue\":\"default\",\"error_message\":\"bam\",\"failed_at\":\"2013-07-20 14:03:42 UTC\",\"retry_count\":10}")
//.........这里部分代码省略.........