Added test for posible deadlock

This commit is contained in:
Trial97
2021-10-20 17:28:14 +03:00
committed by Dan Christian Bogos
parent 7cb1ca95bc
commit cffeb44ade

View File

@@ -19,6 +19,7 @@ import (
"fmt"
"reflect"
"testing"
"time"
"github.com/cgrates/birpc"
"github.com/cgrates/birpc/context"
@@ -552,3 +553,45 @@ func TestCMReload(t *testing.T) {
t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv2)
}
}
func TestCMDeadLock(t *testing.T) {
// to not break the next tests reset the values
tCh := Cache
tCfg := config.CgrConfig()
tCM := connMgr
defer func() {
Cache = tCh
config.SetCgrConfig(tCfg)
connMgr = tCM
}()
cfg := config.NewDefaultCGRConfig()
// define a dummy replication conn
cfg.CacheCfg().ReplicationConns = []string{"test"}
cfg.CacheCfg().Partitions[utils.CacheRPCConnections].Replicate = true
cfg.RPCConns()["test"] = &config.RPCConn{Conns: []*config.RemoteHost{{}}}
config.SetCgrConfig(cfg)
Cache = NewCacheS(cfg, nil, nil)
iCh := make(chan rpcclient.ClientConnector, 1)
iCn := utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)
iCh <- Cache
connMgr = NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{iCn: iCh})
var reply string
connMgr.Call([]string{iCn}, nil, utils.CacheSv1Clear,
new(utils.AttrCacheIDsWithAPIOpts), &reply) // just cache a connection
done := make(chan struct{}) // signal
go func() {
Cache.Clear(nil)
close(done)
}()
select {
case <-done:
case <-time.After(time.Second):
t.Fatal("Deadlock on cache")
}
}