~ps-jenkins/cordova-ubuntu-tests/latestsnapshot-2.11+13.10.20131023-0ubuntu1

« back to all changes in this revision

Viewing changes to tests/autopilot/cordova_ubuntu/tests/test_mobilespec.py

Replaces the sleep() with a proper check for the test suite to finish.

Approved by PS Jenkins bot, Robert Bruce Park.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from __future__ import absolute_import
10
10
 
 
11
import signal
 
12
 
11
13
from testtools.matchers import Contains, Equals
12
14
from autopilot.matchers import Eventually
13
15
 
16
18
from cordova_ubuntu.tests import CordovaUbuntuTestCase
17
19
 
18
20
from time import sleep
19
 
from os import path
20
 
 
 
21
from os import path, kill
 
22
 
 
23
class Alarm(Exception):
 
24
    pass
 
25
 
 
26
def alarm_handler(signum, frame):
 
27
    raise Alarm
 
28
 
 
29
TIMEOUT = 120
21
30
 
22
31
class TestMobileSpec(CordovaUbuntuTestCase):
23
32
 
32
41
        self.assertThat(web_view.loadProgress, Eventually(Equals(100)))
33
42
        # Wait until finished (autotest/pages/all.html)
34
43
        web_view.slots.evalInPageUnsafe("document.addEventListener('junitxml-finished', function (e) { setTimeout(navigator.app.closeApp, 1000); }, false);");
35
 
        # FIXME: Detect window closed
36
 
        sleep(200)
37
 
 
 
44
        # Detect window closed
 
45
        signal.signal(signal.SIGALRM, alarm_handler)
 
46
        signal.alarm(TIMEOUT) # Setup timeout
 
47
        finished = False
 
48
        try:
 
49
            while (self.app.process.poll() is None):
 
50
                # Process still running, sleep a bit
 
51
                sleep(1)
 
52
            signal.alarm(0)
 
53
            finished = True
 
54
        except Alarm:
 
55
            # Timeout reached
 
56
            pass
 
57
        self.assertThat(finished, Equals(True))