| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package kmodule
- import (
- "os"
- "testing"
- "time"
- "gitp78su.ipnodns.ru/svi/kern/v4/d0"
- "gitp78su.ipnodns.ru/svi/kern/v4/d1/mock_env"
- "gitp78su.ipnodns.ru/svi/kern/v4/d2/kern_ctx"
- "gitp78su.ipnodns.ru/svi/kern/v4/d3/mod_ent"
- "gitp78su.ipnodns.ru/svi/kern/v4/d3/mod_spec"
- )
- type tester struct {
- t *testing.T
- mod mod_spec.IKernelModule
- me *mock_env.MockEnv
- owner *d0.LOwner
- ownerPass *d0.OwnerPass
- }
- func TestKernelModule(t *testing.T) {
- owner:=d0.LetOwner(1, "test_isol_kern")
- sf := &tester{
- t: t,
- owner: owner,
- me: mock_env.MakeEnv(owner),
- }
- _ = os.Unsetenv("LOCAL_STORE_PATH")
- _ = os.Setenv("LOCAL_STORE_PATH", "/store/store_module")
- _ = os.Unsetenv("LOCAL_HTTP_URL")
- _ = os.Setenv("LOCAL_HTTP_URL", "http://localhost:18331/")
- fnClear := func() {
- pwd := sf.me.Pwd().String() + "/store/store_module"
- _ = os.RemoveAll(pwd)
- }
- fnClear()
- defer fnClear()
- sf.new()
- sf.run()
- sf.isWork()
- sf.done()
- }
- // Работа после остановки локальной шины.
- func (sf *tester) done() {
- sf.t.Log("done")
- kCtx := kern_ctx.GetKernCtx()
- time.Sleep(time.Millisecond * 250)
- kCtx.Cancel()
- kCtx.Wg().Wait()
- time.Sleep(time.Millisecond * 250)
- }
- // Проверить признак работы.
- func (sf *tester) isWork() {
- sf.t.Log("isWork")
- defer func() {
- if _panic := recover(); _panic == nil {
- sf.t.Fatalf("isWork(): panic==nil")
- }
- }()
- _ = sf.mod.IsWork()
- }
- // Запускает модуль в работу.
- func (sf *tester) run() {
- sf.t.Log("run")
- defer func() {
- if _panic := recover(); _panic == nil {
- sf.t.Fatalf("run(): panic==nil")
- }
- }()
- mod := sf.mod.(*kModule)
- mod.timePhase.Set(5) // Настройка переменной модуля
- sf.mod.Run()
- }
- // Создание нового модуля ядра.
- func (sf *tester) new() {
- sf.t.Log("new")
- sf.newGood1()
- }
- func (sf *tester) newGood1() {
- sf.t.Log("newGood1")
- modName := mod_ent.LetModuleName("test_module")
- sf.mod = NewKernelModule(sf.owner, modName)
- if name := sf.mod.Name(); name.Get() != "test_module" {
- sf.t.Fatalf("newGood1(): name(%v)!='test_module'", name)
- }
- if ctx := sf.mod.Ctx(); ctx == nil {
- sf.t.Fatalf("newGood1(): ctx==nil")
- }
- if _log := sf.mod.Log(); _log == nil {
- sf.t.Fatalf("newGood1(): log==nil")
- }
- _ = sf.mod.Stat()
- _ = sf.mod.Live()
- }
|