Skip to content

Commit

Permalink
#16: Now checking that the port we want to use isn't taken yet
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelkiessling committed Jan 12, 2017
1 parent 13c35e9 commit 9cb652f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions bin/run-testcase.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash

# Starting the proxy as early as possible to minimize the risk of having the port taken by another proxy process
/usr/bin/curl -s -X POST -d "port=$2" http://localhost:9090/proxy
/usr/bin/curl -s -X PUT -d "captureHeaders=1" http://localhost:9090/proxy/$2/har

/usr/bin/Xvfb :$1 -nolisten tcp -ac > /dev/null 2> /dev/null &
XVFB_PID=$!

export DISPLAY=:$1
mkdir /var/tmp/journeymonitor-firefox-profile-$XVFB_PID

/usr/bin/curl -s -X POST -d "port=$2" http://localhost:9090/proxy
/usr/bin/curl -s -X PUT -d "captureHeaders=1" http://localhost:9090/proxy/$2/har
# Firefoxes should not be started in parallel it seems
sleep $[ ( $RANDOM % 10 ) + 1 ]s

/usr/bin/java \
-jar /opt/selenese-runner-java/selenese-runner.jar \
Expand Down
8 changes: 6 additions & 2 deletions src/JourneyMonitor/Monitor/JobRunner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ public function run($retry = 0)
$found = false;
while (!$found) {
$proxyPort = mt_rand(9091, 60000);
if (!file_exists('/var/tmp/journeymonitor-testcase-run-proxyport-' . $proxyPort . '.lock')) {
// https://github.com/journeymonitor/monitor/issues/16:
// "browsermob proxy instance not starting every now and then because port is already taken"
// Only "reserving" a port via the lock file is not enough because browsermob also grabs a lot of
// other ports while requests run over its proxy childs
if ( !file_exists('/var/tmp/journeymonitor-testcase-run-proxyport-' . $proxyPort . '.lock')
&& shell_exec('/usr/bin/lsof -P -i:' . $proxyPort . ' -n -sTCP:LISTEN 2>&1 | /usr/bin/wc -l') === '0\n') {
$found = true;
touch('/var/tmp/journeymonitor-testcase-run-proxyport-' . $proxyPort . '.lock');
}
}

$output = [];
$exitCode = 0;
sleep(mt_rand(0, 10)); // Firefoxes should not be started in parallel it seems
$datetimeRun = new \DateTime('now');

$commandline = '/bin/bash ' .
Expand Down

0 comments on commit 9cb652f

Please sign in to comment.