mod_kctx_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package mod_kctx
  2. import (
  3. "os"
  4. "testing"
  5. "time"
  6. "gitp78su.ipnodns.ru/svi/kern/v4/d0"
  7. "gitp78su.ipnodns.ru/svi/kern/v4/d1/mock_env"
  8. "gitp78su.ipnodns.ru/svi/kern/v4/d2"
  9. "gitp78su.ipnodns.ru/svi/kern/v4/d3/mod_spec"
  10. )
  11. const (
  12. baseUrl = "http://localhost:18360/"
  13. pathStore = "/store/store_kern"
  14. )
  15. type tester struct {
  16. t *testing.T
  17. me *mock_env.MockEnv
  18. kCtx *d2.KernCtx
  19. mod mod_spec.IKernelModule
  20. owner *d0.LOwner
  21. }
  22. func TestModKernelCtx(t *testing.T) {
  23. owner := d0.LetOwner(1, "test_isol_kern_ctx")
  24. sf := &tester{
  25. t: t,
  26. owner: owner,
  27. me: mock_env.MakeEnv(owner),
  28. kCtx: d2.GetKernCtx(),
  29. }
  30. _ = os.Unsetenv("LOCAL_STORE_PATH")
  31. _ = os.Setenv("LOCAL_STORE_PATH", pathStore)
  32. _ = os.Unsetenv("LOCAL_HTTP_URL")
  33. _ = os.Setenv("LOCAL_HTTP_URL", baseUrl)
  34. fnClear := func() {
  35. pwd := sf.me.Pwd().String() + pathStore
  36. _ = os.RemoveAll(pwd)
  37. }
  38. fnClear()
  39. defer fnClear()
  40. sf.kCtx.Set(d0.LetTxt("monolitName"), "test_monolit", "test")
  41. sf.new()
  42. sf.done()
  43. }
  44. // Завершение работы.
  45. func (sf *tester) done() {
  46. sf.t.Log("done")
  47. sf.kCtx.Cancel()
  48. sf.kCtx.Wg().Wait()
  49. if sf.mod.IsWork() {
  50. sf.t.Fatalf("newGood1(): isWork==true")
  51. }
  52. }
  53. // Создание нового модуля HTTP-сервера.
  54. func (sf *tester) new() {
  55. sf.t.Log("new")
  56. // sf.newBad1()
  57. sf.newGood1()
  58. }
  59. func (sf *tester) newGood1() {
  60. sf.t.Log("newGood1")
  61. _ = mock_env.MakeEnv(sf.owner)
  62. _ = os.Unsetenv("LOCAL_HTTP_URL")
  63. _ = os.Setenv("LOCAL_HTTP_URL", "http://localhost:18328/")
  64. sf.mod = GetModuleKernelCtx()
  65. _ = GetModuleKernelCtx()
  66. if sf.mod == nil {
  67. sf.t.Fatalf("newGood1(): mod==nil")
  68. }
  69. go sf.mod.Run()
  70. for {
  71. time.Sleep(time.Millisecond * 1)
  72. if sf.mod.IsWork() {
  73. break
  74. }
  75. }
  76. }
  77. // нет ничего для создания модуля
  78. // func (sf *tester) newBad1() {
  79. // sf.t.Log("newBad1")
  80. // defer func() {
  81. // if _panic := recover(); _panic == nil {
  82. // sf.t.Fatalf("newBad1(): panic==nil")
  83. // }
  84. // }()
  85. // _ = GetModuleKernelCtx()
  86. // }