2012-03-26 13:32:59 +08:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
var worker *Worker
|
|
|
|
|
|
|
|
func init() {
|
2012-05-24 19:21:30 +08:00
|
|
|
worker = New(Unlimited)
|
2012-03-26 13:32:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestWorkerAddServer(t *testing.T) {
|
|
|
|
t.Log("Add local server 127.0.0.1:4730.")
|
|
|
|
if err := worker.AddServer("127.0.0.1:4730"); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2012-05-24 19:21:30 +08:00
|
|
|
if l := len(worker.agents); l != 1 {
|
|
|
|
t.Log(worker.agents)
|
2012-03-26 13:32:59 +08:00
|
|
|
t.Error("The length of server list should be 1.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-24 19:21:30 +08:00
|
|
|
func foobar(job *Job) ([]byte, error) {
|
2012-03-26 13:32:59 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWorkerAddFunction(t *testing.T) {
|
2012-05-24 19:21:30 +08:00
|
|
|
if err := worker.AddFunc("foobar", foobar, 0); err != nil {
|
2012-03-26 13:32:59 +08:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2012-05-24 19:21:30 +08:00
|
|
|
if err := worker.AddFunc("timeout", foobar, 5); err != nil {
|
2012-03-26 13:32:59 +08:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2012-05-24 19:21:30 +08:00
|
|
|
if l := len(worker.funcs); l != 2 {
|
|
|
|
t.Log(worker.funcs)
|
2012-03-26 13:32:59 +08:00
|
|
|
t.Errorf("The length of function map should be %d.", 2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-24 19:21:30 +08:00
|
|
|
func TestWorkerRemoveFunc(t *testing.T) {
|
|
|
|
if err := worker.RemoveFunc("foobar"); err != nil {
|
2012-03-26 13:32:59 +08:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|