kern_ctx_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package kern_ctx
  2. import (
  3. "testing"
  4. "gitp78su.ipnodns.ru/svi/kern/v4/d0"
  5. )
  6. type tester struct {
  7. t *testing.T
  8. owner *d0.LOwner
  9. }
  10. func TestKernelCtx(t *testing.T) {
  11. sf := &tester{
  12. t: t,
  13. owner: d0.LetOwner(1, "test_kernel_ctx"),
  14. }
  15. sf.new()
  16. }
  17. var counter *d0.LTxt
  18. // Создание контекста ядра.
  19. func (sf *tester) new() {
  20. sf.t.Log("new")
  21. counter = d0.LetTxt(sf.owner, "counter")
  22. kCtx := GetKernCtx()
  23. if kCtx == nil {
  24. sf.t.Fatalf("new(): KernelCtx==nil")
  25. }
  26. if ctx := kCtx.CtxBg(); ctx != kernCtx.ctxBg {
  27. sf.t.Fatalf("new(): ctx!=ctxBg")
  28. }
  29. if ctx := kCtx.SelfCtx(); ctx == nil {
  30. sf.t.Fatalf("new(): ctx==nil")
  31. }
  32. kCtx.Set(counter, 5, "test_counter")
  33. if kCtx.Get(counter) == nil {
  34. sf.t.Fatalf("new(): counter==nil")
  35. }
  36. res := kCtx.Get(counter)
  37. ctxVal := res.Hassert("new()")
  38. val := ctxVal.Val().(d0.Num)
  39. if val != 5 {
  40. sf.t.Fatalf("new(): counter(%v)!=5", val)
  41. }
  42. kCtx.Del(counter)
  43. kCtx.Cancel()
  44. kCtx.Wait()
  45. kCtx = GetKernCtx()
  46. if kCtx == nil {
  47. sf.t.Fatalf("new(): KernelCtx==nil")
  48. }
  49. if wg := kCtx.Wg(); wg == nil {
  50. sf.t.Fatalf("new(): IKernelWg==nil")
  51. }
  52. if keep := kCtx.Keeper(); keep == nil {
  53. sf.t.Fatalf("new(): IKernelKeeper==nil")
  54. }
  55. }