mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 10:36:24 +05:00
Added test for posible deadlock
This commit is contained in:
committed by
Dan Christian Bogos
parent
7cb1ca95bc
commit
cffeb44ade
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user