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.

пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package gearman
  2. import (
  3. "testing"
  4. "os"
  5. )
  6. var worker *Worker
  7. func init() {
  8. worker = NewWorker()
  9. }
  10. func TestWorkerAddServer(t *testing.T) {
  11. t.Log("Add local server 127.0.0.1:4730.")
  12. if err := worker.AddServer("127.0.0.1:4730"); err != nil {
  13. t.Error(err)
  14. }
  15. if l := len(worker.clients); l != 1 {
  16. t.Log(worker.clients)
  17. t.Error("The length of server list should be 1.")
  18. }
  19. }
  20. func foobar(job *WorkerJob) ([]byte, os.Error) {
  21. return nil, nil
  22. }
  23. func TestWorkerAddFunction(t *testing.T) {
  24. if err := worker.AddFunction("foobar", foobar, 0); err != nil {
  25. t.Error(err)
  26. }
  27. if err := worker.AddFunction("timeout", foobar, 5); err != nil {
  28. t.Error(err)
  29. }
  30. if l := len(worker.functions); l != 2 {
  31. t.Log(worker.functions)
  32. t.Errorf("The length of function map should be %d.", 2)
  33. }
  34. }
  35. func TestWorkerEcho(t * testing.T) {
  36. if err := worker.Echo([]byte("Hello World")); err != nil {
  37. t.Error(err)
  38. }
  39. }
  40. /*
  41. func TestWorkerResult(t *testing.T) {
  42. if job := worker.LastResult(); job == nil {
  43. t.Error("Nothing in result.")
  44. } else {
  45. t.Log(job)
  46. }
  47. }
  48. */
  49. func TestWorkerRemoveFunction(t * testing.T) {
  50. if err := worker.RemoveFunction("foobar"); err != nil {
  51. t.Error(err)
  52. }
  53. }
  54. func TestWorkerReset(t * testing.T) {
  55. if err := worker.Reset(); err != nil {
  56. t.Error(err)
  57. }
  58. }
  59. func TestWorkerClose(t *testing.T) {
  60. if err := worker.Close(); err != nil {
  61. t.Error(err)
  62. }
  63. }