kernel_ctx_test.go 899 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package kernel_ctx
  2. import (
  3. "testing"
  4. )
  5. type tester struct {
  6. t *testing.T
  7. }
  8. func TestKernelCtx(t *testing.T) {
  9. sf := &tester{
  10. t: t,
  11. }
  12. sf.new()
  13. }
  14. // Создание контекста ядра
  15. func (sf *tester) new() {
  16. sf.t.Log("new")
  17. ctx := ПолучЯдроКонтекст()
  18. if ctx == nil {
  19. sf.t.Fatalf("new(): KernelCtx==nil")
  20. }
  21. if ctx := ctx.КонтФон(); ctx != kernCtx.ctxBg {
  22. sf.t.Fatalf("new(): ctx!=ctxBg")
  23. }
  24. if ctx := ctx.Конт(); ctx != kernCtx.ctx {
  25. sf.t.Fatalf("new(): ctx!=kernel.ctx")
  26. }
  27. ctx.Уст("counter", 5)
  28. counter := ctx.Получ("counter").(int)
  29. if counter != 5 {
  30. sf.t.Fatalf("new(): counter(%v)!=5", counter)
  31. }
  32. ctx.Отменить()
  33. ctx.Ждать()
  34. ctx = ПолучЯдроКонтекст()
  35. if ctx == nil {
  36. sf.t.Fatalf("new(): KernelCtx==nil")
  37. }
  38. if wg := ctx.Оп(); wg == nil {
  39. sf.t.Fatalf("new(): IKernelWg==nil")
  40. }
  41. }