func Test_running_core_MultipleCore(t *testing.T) { logging.Debug("") // logging.SetLevel("debug") rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(configs["file"])) if err != nil { t.Errorf("err %v", err) return } err = UpdateRunningCore(rconf) if err != nil { t.Errorf("err %v", err) } if the_core == nil { t.Errorf("err %v", err) } for i := 0; i < 100; i++ { err = UpdateRunningCore(rconf) if err != nil { t.Errorf("err %v", err) } if the_core == nil { t.Errorf("err %v", err) } } }
// make sure heartbeat is always created func Test_running_core_UpdateRunningCore_Alwasy_Heartbeat(t *testing.T) { data := []byte(` client: transport_dummy: name: "dummy" `) rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("failed to read runtime config. err %v", err) return } core, hook, err := create_running_core_hooked(rconf, true) if err != nil { t.Errorf("err %v", err) return } if core == nil { t.Errorf("err %v", err) } // closed_chan := make(chan int) time.AfterFunc(time.Second*1, func() { core.Close() }) timeout := time.After(time.Second * 2) // t.Logf("core: %+v", core) // t.Logf("hook: %+v", hook) heartbeat_exists := false main_loop: for { select { // case <-closed_chan: // break main_loop case md, opening := <-hook.Hook(): if opening == false { t.Log("HookBackend closed") break main_loop } for _, dp := range md { res, _ := dp.MarshalJSON() fmt.Println("--> dp", string(res)) if dp.Metric == "hickwall.client.alive" { heartbeat_exists = true break main_loop } } case <-timeout: t.Error("something is blocking") break main_loop } } if heartbeat_exists == false { t.Error("heartbeat didn't show up") } }
func Test_use_config_windows_UseConfigCreateSubscription_fails(t *testing.T) { for key, data := range sub_fails_configs { rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("%s, err %v", key, err) return } subs, err := UseConfigCreateSubscription(rconf) if err == nil { t.Errorf("%s should fail but not", key) } if len(subs) > 0 { t.Errorf("%s should fail but not", key) } t.Logf("%s - %v", key, subs) } }
func Test_use_config_windows_UseConfigCreateCollectors_Fails(t *testing.T) { for key, data := range fail_configs { rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("%s, err %v", key, err) return } clrs, err := UseConfigCreateCollectors(rconf) if err == nil { t.Errorf("%s should fail but not", key) } if len(clrs) > 0 { t.Errorf("%s should fail but not", key) } t.Logf("%s - %v", key, clrs) } }
func Test_use_config_windows_UseConfigCreateCollectors_1(t *testing.T) { for key, data := range configs { rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("%s, err %v", key, err) return } clrs, err := UseConfigCreateCollectors(rconf) if err != nil { t.Errorf("%s, err %v", key, err) } if len(clrs) <= 0 { t.Errorf("%s, nothing created", key) } t.Logf("%s - %v", key, clrs) } }
func Test_running_core_UpdateRunningCore(t *testing.T) { for key, data := range configs { rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("failed read runtimeconfig: %s, err %v", key, err) return } err = UpdateRunningCore(rconf) if err != nil { t.Errorf("failed create running core: %s, err %v", key, err) } if the_core == nil { t.Errorf("core is nil: %s, err %v", key, err) } t.Logf("%s - %+v", key, the_core) } }
func Test_UseConfig_CreateBackends_Fails(t *testing.T) { for key, data := range fail_configs { rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("%s, err %v", key, err) return } bks, err := UseConfigCreateBackends(rconf) if err == nil { t.Errorf("%s, should fail but not", key) } if len(bks) > 0 { t.Errorf("%s, should fail but not", key) } t.Logf("%s - %v", key, bks) } }
func Test_UseConfig_CreateBackends(t *testing.T) { for key, data := range configs { rconf, err := config.ReadRuntimeConfig(bytes.NewBuffer(data)) if err != nil { t.Errorf("%s, err %v", key, err) return } bks, err := UseConfigCreateBackends(rconf) if err != nil { t.Errorf("%s, err %v", key, err) } if len(bks) <= 0 { t.Errorf("%s, nothing created", key) } t.Logf("%s - %v", key, bks) } }