gearman-go/src/pkg/gearman/gearman_test.go

62 lines
1.2 KiB
Go
Raw Normal View History

2011-05-16 17:26:32 +08:00
package gearman
2011-03-15 20:21:42 +08:00
import (
2011-05-16 17:26:32 +08:00
"testing"
2011-03-15 20:21:42 +08:00
)
var worker *Worker
func init() {
worker = NewWorker()
}
2011-05-16 17:26:32 +08:00
func TestAddServer(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)
}
2011-05-17 18:22:12 +08:00
2011-05-16 17:26:32 +08:00
if l := len(worker.servers); l != 1 {
t.Log(worker.servers)
t.Error("The length of server list should be 1.")
}
2011-03-15 20:21:42 +08:00
}
func TestAddFunction(t *testing.T) {
f := func(job *Job) []byte {
return nil
}
if err := worker.AddFunction("foobar", f); err != nil {
t.Error(err)
}
2011-05-17 20:32:36 +08:00
if err := worker.AddFunction("timeout", f); err != nil {
t.Error(err)
}
if l := len(worker.functions); l != 2 {
t.Log(worker.functions)
2011-05-17 20:32:36 +08:00
t.Errorf("The length of function map should be %d.", 2)
}
}
func TestEcho(t * testing.T) {
go worker.Work()
if err := worker.Echo([]byte("Hello World")); err != nil {
t.Error(err)
}
}
2011-05-17 18:22:12 +08:00
func TestResult(t *testing.T) {
if job := worker.Result(); job == nil {
2011-05-17 20:32:36 +08:00
//t.Error("Nothing in result.")
2011-05-17 18:22:12 +08:00
} else {
t.Log(job)
}
}
func TestClose(t *testing.T) {
if err := worker.Close(); err != nil {
t.Error(err)
}
}