Framework for automated call testing

This commit is contained in:
DanB
2015-03-13 19:16:11 +01:00
parent ef0990b9dd
commit de96c183cf
3 changed files with 80 additions and 0 deletions

View File

@@ -916,6 +916,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
for idx, dc := range dcs {
dcsKeys[idx] = engine.DERIVEDCHARGERS_PREFIX + dc
}
engine.Logger.Info("ApierV1.LoadTariffPlanFromFolder, reloading cache.")
if err := self.RatingDb.CacheRating(dstKeys, rpKeys, rpfKeys, rpAlsKeys, lcrKeys); err != nil {
return err
}
@@ -923,6 +924,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder,
return err
}
if self.Sched != nil {
engine.Logger.Info("ApierV1.LoadTariffPlanFromFolder, reloading scheduler.")
self.Sched.LoadActionTimings(self.AccountDb)
self.Sched.Restart()
}

View File

@@ -19,9 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"bytes"
"fmt"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
"github.com/kr/pty"
"io"
"os"
"os/exec"
"path"
"time"
@@ -106,3 +110,76 @@ func LoadTariffPlanFromFolder(tpPath string, ratingDb RatingStorage, accountingD
}
return nil
}
type PjsuaAccount struct {
Id, Username, Password, Realm, Registrar string
}
// Returns file reference where we can write to control pjsua in terminal
func StartPjsuaListener(acnts []*PjsuaAccount, waitMs int) (*os.File, error) {
cmdArgs := []string{"--local-port=5070", "--null-audio", "--auto-answer=200", "--max-calls=32", "--app-log-level=0"}
for idx, acnt := range acnts {
if idx != 0 {
cmdArgs = append(cmdArgs, "--next-account")
}
cmdArgs = append(cmdArgs, "--id="+acnt.Id, "--registrar="+acnt.Registrar, "--username="+acnt.Username, "--password="+acnt.Password, "--realm="+acnt.Realm)
}
pjsuaPath, err := exec.LookPath("pjsua")
if err != nil {
return nil, err
}
pjsua := exec.Command(pjsuaPath, cmdArgs...)
fPty, err := pty.Start(pjsua)
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
io.Copy(os.Stdout, buf) // Free the content since otherwise pjsua will not start
time.Sleep(time.Duration(waitMs) * time.Millisecond) // Give time to rater to fire up
return fPty, nil
}
func PjsuaCallUri(acnt *PjsuaAccount, dstUri string, callDur time.Duration, localPort int) error {
cmdArgs := []string{"--null-audio", "--app-log-level=0", fmt.Sprintf("--local-port=%d", localPort), fmt.Sprintf("--duration=%d", int(callDur.Seconds())),
"--id=" + acnt.Id, "--username=" + acnt.Username, "--password=" + acnt.Password, "--realm=" + acnt.Realm, dstUri}
pjsuaPath, err := exec.LookPath("pjsua")
if err != nil {
return err
}
pjsua := exec.Command(pjsuaPath, cmdArgs...)
fPty, err := pty.Start(pjsua)
if err != nil {
return err
}
buf := new(bytes.Buffer)
io.Copy(os.Stdout, buf)
go func() {
time.Sleep(callDur + (time.Duration(2) * time.Second))
fPty.Write([]byte("q\n")) // Destroy the listener
}()
return nil
}
func KillFreeSWITCH(waitMs int) error {
if err := exec.Command("pkill", "freeswitch").Run(); err != nil {
return err
}
time.Sleep(time.Duration(waitMs) * time.Millisecond)
return nil
}
func StopFreeSWITCH(scriptPath string, waitStop int) error {
if err := exec.Command(scriptPath, "stop").Run(); err != nil {
return err
}
return nil
}
func StartFreeSWITCH(scriptPath string, waitMs int) error {
KillFreeSWITCH(1000)
if err := exec.Command(scriptPath, "start").Run(); err != nil {
return err
}
time.Sleep(time.Duration(waitMs) * time.Millisecond) // Give time to rater to fire up
return nil
}

View File

@@ -41,6 +41,7 @@ var cfg *config.CGRConfig
var rater *rpc.Client
var testLocal = flag.Bool("local", false, "Perform the tests only on local test environment, not by default.") // This flag will be passed here via "go test -local" args
var testCalls = flag.Bool("calls", false, "Run test calls simulation, not by default.")
var dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
var storDbType = flag.String("stordb_type", "mysql", "The type of the storDb database <mysql>")
var waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for rater to start and cache")