server_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved.
  2. package market
  3. // 本文件测试server的rpc接口
  4. import (
  5. "github.com/wangch/rpc"
  6. "log"
  7. "testing"
  8. "time"
  9. )
  10. var (
  11. server *Server
  12. subCode = time.Now().UnixNano()
  13. )
  14. func newServer(t *testing.T) {
  15. // newDB()
  16. if server != nil {
  17. return
  18. }
  19. conf := DefaultServerConf
  20. conf.DsMap[Lmax].Run = false
  21. s := NewServer(nil, conf.DataDir, "")
  22. server = s
  23. go s.ListenAndServe(":19526", ":19527")
  24. }
  25. func TestSubMarket(t *testing.T) {
  26. newServer(t)
  27. client, err := rpc.Dial("tcp", "localhost:19526")
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. log.Println("@@@@@@@: connected server OK!")
  32. f := func(v interface{}, err error) error {
  33. if err != nil {
  34. t.Error(err)
  35. return err
  36. }
  37. mk, ok := v.(*Market)
  38. if !ok {
  39. t.Error("market.Client.subMarket error: v.(*Market) is NOT ok")
  40. return err
  41. }
  42. log.Println("@@@@@@@:", mk)
  43. return nil
  44. }
  45. args := SubArgs{"4001", subCode, false}
  46. var reply Market
  47. err = client.Sub("Server.SubMarket", args, &reply, f)
  48. if err != nil {
  49. t.Error(err)
  50. }
  51. time.Sleep(time.Minute)
  52. }
  53. func TestUnsubMarket(t *testing.T) {
  54. }
  55. func TestGetHistory(t *testing.T) {
  56. }
  57. func TestGetLastTicks(t *testing.T) {
  58. }
  59. func TestGetLastCandles(t *testing.T) {
  60. }