Random Sound Playback for Load Testing
Random Sound Playback for Load Testing
When you need to simulate active calls for load testing or verify audio paths across a system, this extensionA dialplan entry that matches a dialed number or pattern within a context and triggers a sequence of prioritized steps. plays random sounds from Asterisk's sound library in an infinite loop. Point a SIPSession Initiation Protocol, the standard signaling protocol used to set up, manage, and tear down VoIP calls between Asterisk and phones or carriers. load generator at it and watch how the system handles sustained call volume.
The dialplan
[testing]
exten => 999,1,Answer()
same => n(loop),Set(RANDSOUND=${SHELL(ls /var/lib/asterisk/sounds/en/*.wav 2>/dev/null | shuf -n1 | xargs -I{} basename {} .wav | tr -d '\n')})
same => n,GotoIf($["${RANDSOUND}" = ""]?done)
same => n,Playback(${RANDSOUND})
same => n,Goto(loop)
same => n(done),Hangup()
Each iteration picks a random .wav file from the English sound directory, strips the extension, and plays it. The loop runs until the caller hangs up.
Generating test calls
From the Asterisk CLI, originate a batch of test calls:
# Single test call (30 second timeout)
asterisk -rx 'channel originate Local/999@testing application Wait 30'
# 10 concurrent calls
for i in $(seq 1 10); do
asterisk -rx "channel originate Local/999@testing application Wait 60" &
done
Notes
SHELL()executes a shell command from the dialplanThe core call-routing configuration of Asterisk, written mostly in extensions.conf as contexts, extensions, and priorities that decide how every call is handled. Full definition →. Keep this in a testing contextA named section of the dialplan that groups extensions. Calls enter a specific context and can only reach extensions visible from it, making contexts the basic unit of call routing and security. only, never expose it to untrusted callers.- If your sounds are in a different path, adjust the
lscommand accordingly. - For heavier load testing, use a dedicated tool like SIPp rather than CLI-originated calls.
User Notes
Know a tip or gotcha for this topic? Share it below and help others.
Contribute a note
Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.