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.
 
 
 

73 lines
1.5 KiB

  1. package worker
  2. import "testing"
  3. var worker *Worker
  4. func init() {
  5. worker = NewWorker()
  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.clients); l != 1 {
  13. t.Log(worker.clients)
  14. t.Error("The length of server list should be 1.")
  15. }
  16. }
  17. func foobar(job *WorkerJob) ([]byte, error) {
  18. return nil, nil
  19. }
  20. func TestWorkerAddFunction(t *testing.T) {
  21. if err := worker.AddFunction("foobar", foobar, 0); err != nil {
  22. t.Error(err)
  23. }
  24. if err := worker.AddFunction("timeout", foobar, 5); err != nil {
  25. t.Error(err)
  26. }
  27. if l := len(worker.functions); l != 2 {
  28. t.Log(worker.functions)
  29. t.Errorf("The length of function map should be %d.", 2)
  30. }
  31. }
  32. func TestWorkerEcho(t *testing.T) {
  33. if err := worker.Echo([]byte("Hello World")); err != nil {
  34. t.Error(err)
  35. }
  36. }
  37. /*
  38. func TestWorkerResult(t *testing.T) {
  39. if job := worker.LastResult(); job == nil {
  40. t.Error("Nothing in result.")
  41. } else {
  42. t.Log(job)
  43. }
  44. }
  45. */
  46. func TestWorkerRemoveFunction(t *testing.T) {
  47. if err := worker.RemoveFunction("foobar"); err != nil {
  48. t.Error(err)
  49. }
  50. }
  51. func TestWorkerReset(t *testing.T) {
  52. if err := worker.Reset(); err != nil {
  53. t.Error(err)
  54. }
  55. }
  56. func TestWorkerClose(t *testing.T) {
  57. if err := worker.Close(); err != nil {
  58. t.Error(err)
  59. }
  60. }