You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
971 B

  1. package worker
  2. import "testing"
  3. var worker *Worker
  4. func init() {
  5. worker = New(Unlimited)
  6. }
  7. func TestWorkerAddServer(t *testing.T) {
  8. t.Log("Add local server 127.0.0.1:4730.")
  9. if err := worker.AddServer("127.0.0.1:4730"); err != nil {
  10. t.Error(err)
  11. }
  12. if l := len(worker.agents); l != 1 {
  13. t.Log(worker.agents)
  14. t.Error("The length of server list should be 1.")
  15. }
  16. }
  17. func foobar(job *Job) ([]byte, error) {
  18. return nil, nil
  19. }
  20. func TestWorkerAddFunction(t *testing.T) {
  21. if err := worker.AddFunc("foobar", foobar, 0); err != nil {
  22. t.Error(err)
  23. }
  24. if err := worker.AddFunc("timeout", foobar, 5); err != nil {
  25. t.Error(err)
  26. }
  27. if l := len(worker.funcs); l != 2 {
  28. t.Log(worker.funcs)
  29. t.Errorf("The length of function map should be %d.", 2)
  30. }
  31. }
  32. func TestWorkerRemoveFunc(t *testing.T) {
  33. if err := worker.RemoveFunc("foobar"); err != nil {
  34. t.Error(err)
  35. }
  36. }