exp_test.go 661 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package service
  2. import (
  3. "fmt"
  4. "sync"
  5. "testing"
  6. "time"
  7. "encoding/json"
  8. "go-common/app/job/live-userexp/conf"
  9. "go-common/app/job/live-userexp/model"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. once sync.Once
  14. s *Service
  15. )
  16. func startService() {
  17. if err := conf.Init(); err != nil {
  18. panic(fmt.Sprintf("conf.Init() error(%v)", err))
  19. }
  20. s = New(conf.Conf)
  21. }
  22. func TestLevelCacheUpdate(t *testing.T) {
  23. Convey("Cache update", t, func() {
  24. once.Do(startService)
  25. time.Sleep(time.Second)
  26. m := &model.Message{}
  27. exp := &model.Exp{}
  28. m.New, _ = json.Marshal(exp)
  29. m.Old, _ = json.Marshal(exp)
  30. s.levelCacheUpdate(m.New, m.Old)
  31. })
  32. }