Files
cgrates/analyzers/connector_test.go
ionutboangiu 2c1a90c9c6 Optimize and fix unstable tests
Revise backup loop tests to not rely on time.Sleep anymore and remove
unused fields from them.

Removed 3ns TTL from tpreader test dataDB configuration that caused in-
consistent results.

Ensure connManager cache is reloaded in filter tests. Before they could
cause deadlocks.

Remove redundant inits, global vars and setup tests for debit and
accounts tests.

Optimize some analyzers tests.
2024-04-11 18:23:57 +02:00

67 lines
1.9 KiB
Go

/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package analyzers
import (
"errors"
"os"
"runtime"
"testing"
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
type mockConnector struct{}
func (c *mockConnector) Call(_ *context.Context, _ string, _, _ any) (err error) {
return errors.New("error")
}
func TestNewAnalyzeConnector(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.AnalyzerSCfg().DBPath = "/tmp/analyzers"
if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(cfg.AnalyzerSCfg().DBPath, 0700); err != nil {
t.Fatal(err)
}
anz, err := NewAnalyzerService(cfg)
if err != nil {
t.Fatal(err)
}
rpc := anz.NewAnalyzerConnector(new(mockConnector), utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012")
if err = rpc.Call(context.Background(), utils.CoreSv1Ping, "args", "reply"); err == nil || err.Error() != "error" {
t.Errorf("Expected 'error' received %v", err)
}
time.Sleep(15 * time.Millisecond)
runtime.Gosched()
if cnt, err := anz.db.DocCount(); err != nil {
t.Fatal(err)
} else if cnt != 1 {
t.Errorf("Expected only one document received:%v", cnt)
}
if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil {
t.Fatal(err)
}
}