~pwlars/ubuntu-test-cases/krillin-recovery

« back to all changes in this revision

Viewing changes to selftests/test_reboot_and_wait.py

  • Committer: Andy Doan
  • Date: 2013-10-21 02:19:35 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: andy.doan@canonical.com-20131021021935-9v30ul1w0ff7yy30
fix bugs found in run-autopilot.sh

1: When unlock screen failed the whole script was ended. This makes sure
we just fail that single app test and continue trying other apps.

2: The reboot_wait logic isn't resiliant enough. Before we had "mega"
jobs (ie jenkins.sh) it was okay if a test occassionally failed to
get active networking. However, in this new script that failure can
cause all the remaining tests to not get run. The idea is to create
a reboot-and-wait script that will retry 3 times before giving up.

3: Update the system settle "classname" for junit. The issue I'm
seeing is that the junit results viewer in jenkins isn't correlating
the settle failures with the testsuite it happened in. This makes sure
the 2 are tied together.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Ubuntu Test Cases for Touch
 
2
# Copyright 2013 Canonical Ltd.
 
3
 
 
4
# This program is free software: you can redistribute it and/or modify it
 
5
# under the terms of the GNU General Public License version 3, as published
 
6
# by the Free Software Foundation.
 
7
 
 
8
# This program is distributed in the hope that it will be useful, but
 
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
# PURPOSE.  See the GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License along
 
14
# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 
 
16
from __future__ import print_function
 
17
 
 
18
import imp
 
19
import mock
 
20
import os
 
21
import unittest
 
22
 
 
23
 
 
24
class TestRebootAndWait(unittest.TestCase):
 
25
 
 
26
    """Simple set of tests to make sure the reboot-and-wait command works."""
 
27
 
 
28
    def setUp(self):
 
29
        # do some trickery to load this as module
 
30
        module = 'reboot-and-wait'
 
31
        fname = os.path.join(os.path.dirname(__file__), '../scripts', module)
 
32
        m = imp.load_source(module, fname)
 
33
        self._main = m.main
 
34
        self._get_parser = m._get_arg_parser
 
35
 
 
36
    @mock.patch('phabletutils.device.AndroidBridge.reboot')
 
37
    def testRebootFail(self, reboot):
 
38
        reboot.side_effect = RuntimeError('foo')
 
39
        args = self._get_parser().parse_args([])
 
40
        with self.assertRaisesRegexp(RuntimeError, 'foo'):
 
41
            self._main(args)
 
42
 
 
43
    @mock.patch('phabletutils.device.AndroidBridge.reboot')
 
44
    @mock.patch('phabletutils.device.AndroidBridge.wait_for_device')
 
45
    def testWaitForDeviceFail(self, wait_for, reboot):
 
46
        wait_for.side_effect = RuntimeError('foo')
 
47
        args = self._get_parser().parse_args([])
 
48
        with self.assertRaisesRegexp(RuntimeError, 'foo'):
 
49
            self._main(args)
 
50
        reboot.assert_called_once_with()
 
51
 
 
52
    @mock.patch('phabletutils.device.AndroidBridge.reboot')
 
53
    @mock.patch('phabletutils.device.AndroidBridge.wait_for_device')
 
54
    @mock.patch('phabletutils.device.AndroidBridge.wait_for_network')
 
55
    def testRetries(self, wait_for_net, wait_for_dev, reboot):
 
56
        args = self._get_parser().parse_args([])
 
57
        wait_for_net.side_effect = RuntimeError('foo')
 
58
        self.assertEquals(1, self._main(args))
 
59
        self.assertEquals(args.num_tries, reboot.call_count)
 
60
 
 
61
        # now make sure it can recover after a single network failure
 
62
        reboot.reset_mock()
 
63
        wait_for_net.reset_mock()
 
64
        wait_for_net.side_effect = [RuntimeError('foo'), None]
 
65
        self.assertEquals(0, self._main(args))
 
66
        self.assertEquals(2, reboot.call_count)