Example #1
0
def it_times_out():
    assert_command(
        ('pgctl-2015', 'start'),
        '''\
==> playground/slow-startup/stdout.log <==

==> playground/slow-startup/stderr.log <==
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: 'slow-startup' timed out at 2 seconds: not ready
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/slow-startup/stdout.log <==

==> playground/slow-startup/stderr.log <==
pgctl-poll-ready: timeout while waiting for ready
''',
        '',
        0,
    )
Example #2
0
def it_times_out():
    assert_command(
        ('pgctl-2015', 'start'),
        '''\
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/log <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1,
        norm=norm.pgctl,
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
        '',
        0,
        norm=norm.pgctl,
    )
Example #3
0
def it_times_out():
    assert_command(
        ('pgctl', 'start'),
        '''\
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/log <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/slow-startup/log
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1,
        norm=norm.pgctl,
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
        '',
        0,
        norm=norm.pgctl,
    )
Example #4
0
    def it_fails_by_leaking_runaway_process_on_stop(self):
        check_call(('pgctl', 'start'))
        assert_svstat('playground/sweet', state='up')

        assert_command(
            ('pgctl', 'stop'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, these runaway processes did not stop:
{PS-HEADER}
{PS-STATS} sleep 2.5

There are two ways you can fix this:
  * temporarily: pgctl stop sweet --force
  * permanently: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/sweet/logs/current
[pgctl] ERROR: Some services failed to stop: sweet
''',
            1,
            norm=norm.pgctl,
        )
Example #5
0
def it_times_out():
    assert_command(
        ('pgctl-2015', 'start'),
        '''\
''',
        '''\
[pgctl] Starting: slow-startup
[pgctl] ERROR: service 'slow-startup' failed to start after {TIME} seconds, its status is up (pid {PID}) {TIME} seconds
==> playground/slow-startup/log <==
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/slow-startup/log
[pgctl] ERROR: Some services failed to start: slow-startup
''',
        1,
        norm=norm.pgctl,
    )
    assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)

    assert_command(
        ('pgctl-2015', 'log'),
        '''\
==> playground/slow-startup/log <==
{TIMESTAMP} pgctl-poll-ready: service is stopping -- quitting the poll
''',
        '',
        0,
        norm=norm.pgctl,
    )
Example #6
0
def it_can_succeed():
    import mock
    with mock.patch.dict(os.environ, [('PGCTL_TIMEOUT', '5')]):
        assert_command(
            ('pgctl-2015', 'start'),
            '',
            '[pgctl] Starting: slow-startup\n[pgctl] Started: slow-startup\n',
            0
        )
    assert_svstat('playground/slow-startup', state='ready')
Example #7
0
def it_can_succeed():
    from mock import patch, ANY
    with patch.dict(os.environ, [('PGCTL_TIMEOUT', str(SLOW_STARTUP_TIME))]):
        assert_command(
            ('pgctl', 'start'),
            '',
            #'[pgctl] Starting: slow-startup\n[pgctl] Started: slow-startup\n',
            ANY,
            0)
    assert_svstat('playground/slow-startup', state='ready')
Example #8
0
def it_can_succeed():
    from mock import patch, ANY
    with patch.dict(os.environ, [('PGCTL_TIMEOUT', str(SLOW_STARTUP_TIME))]):
        assert_command(
            ('pgctl-2015', 'start'),
            '',
            #'[pgctl] Starting: slow-startup\n[pgctl] Started: slow-startup\n',
            ANY,
            0
        )
    assert_svstat('playground/slow-startup', state='ready')
Example #9
0
    def it_is_just_stop_then_start(self, in_example_dir):
        assert_command(
            ('pgctl', 'restart', 'sleep'),
            '',
            '''\
[pgctl] Already stopped: sleep
[pgctl] Starting: sleep
[pgctl] Started: sleep
''',
            0,
        )
        assert_svstat('playground/sleep', state='up')
Example #10
0
    def it_is_just_stop_then_start(self, in_example_dir):
        assert_command(
            ('pgctl', 'restart', 'sleep'),
            '',
            '''\
[pgctl] Already stopped: sleep
[pgctl] Starting: sleep
[pgctl] Started: sleep
''',
            0,
        )
        assert_svstat('playground/sleep', state='up')
Example #11
0
    def it_is_just_stop_then_start(self, in_example_dir):
        assert_command(
            ("pgctl-2015", "restart", "sleep"),
            "",
            """\
[pgctl] Stopping: sleep
[pgctl] Stopped: sleep
[pgctl] Starting: sleep
[pgctl] Started: sleep
""",
            0,
        )
        assert_svstat("playground/sleep", state="up")
Example #12
0
    def it_fails_by_default(self):
        check_call(('pgctl-2015', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl-2015', 'stop'),
            '''\
==> playground/sweet/stdout.log <==
sweet

==> playground/sweet/stderr.log <==
sweet_error
''',
            S(self.LOCKERROR.format(service='sweet', time='1\\.5', cmd='sleep 2\\.25')),
            1,
        )
Example #13
0
    def it_also_works_when_up(self, in_example_dir):
        check_call(('pgctl', 'start', 'sleep'))
        assert_svstat('playground/sleep', state='up')

        assert_command(
            ('pgctl', 'restart', 'sleep'),
            '',
            '''\
[pgctl] Stopping: sleep
[pgctl] Stopped: sleep
[pgctl] Starting: sleep
[pgctl] Started: sleep
''',
            0,
        )
        assert_svstat('playground/sleep', state='up')
Example #14
0
    def it_also_works_when_up(self, in_example_dir):
        check_call(('pgctl', 'start', 'sleep'))
        assert_svstat('playground/sleep', state='up')

        assert_command(
            ('pgctl', 'restart', 'sleep'),
            '',
            '''\
[pgctl] Stopping: sleep
[pgctl] Stopped: sleep
[pgctl] Starting: sleep
[pgctl] Started: sleep
''',
            0,
        )
        assert_svstat('playground/sleep', state='up')
Example #15
0
    def it_succeeds_on_second_stop_after_some_delay(self):
        check_call(('pgctl', 'start'))
        assert_svstat('playground/sweet', state='up')

        with pytest.raises(subprocess.CalledProcessError):
            check_call(('pgctl', 'stop'))

        time.sleep(3)
        assert_command(
            ('pgctl', 'stop'),
            '',
            '''\
[pgctl] Already stopped: sweet
''',
            0,
            norm=norm.pgctl,
        )
Example #16
0
    def it_fails_by_default(self):
        check_call(('pgctl-2015', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl-2015', 'stop'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, its status is ready (pid {PID}) {TIME} seconds
==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl] ERROR: Some services failed to stop: sweet
''',
            1,
            norm=norm.pgctl,
        )
Example #17
0
    def it_stops_multiple_services(self, in_example_dir):
        check_call(('pgctl-2015', 'start', 'sleep', 'tail'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state='up')

        check_call(('pgctl-2015', 'stop', 'sleep', 'tail'))

        assert_svstat('playground/sleep', state=SvStat.UNSUPERVISED)
        assert_svstat('playground/tail', state=SvStat.UNSUPERVISED)
Example #18
0
    def it_stops_multiple_services(self, in_example_dir):
        check_call(('pgctl', 'start', 'sleep', 'tail'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state='up')

        check_call(('pgctl', 'stop', 'sleep', 'tail'))

        assert_svstat('playground/sleep', state=SvStat.UNSUPERVISED)
        assert_svstat('playground/tail', state=SvStat.UNSUPERVISED)
Example #19
0
    def it_stops_multiple_services(self, in_example_dir):
        check_call(("pgctl-2015", "start", "sleep", "tail"))

        assert_svstat("playground/sleep", state="up")
        assert_svstat("playground/tail", state="up")

        check_call(("pgctl-2015", "stop", "sleep", "tail"))

        assert_svstat("playground/sleep", state=SvStat.UNSUPERVISED)
        assert_svstat("playground/tail", state=SvStat.UNSUPERVISED)
Example #20
0
    def it_fails_by_default(self):
        check_call(('pgctl-2015', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl-2015', 'stop'),
            '''\
==> playground/sweet/stdout.log <==
sweet

==> playground/sweet/stderr.log <==
sweet_error
''',
            S(
                self.LOCKERROR.format(service='sweet',
                                      time='1\\.5',
                                      cmd='sleep 2\\.25')),
            1,
        )
Example #21
0
    def it_succeeds_on_forceful_stop(self):
        check_call(('pgctl', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl', 'stop', '--force'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] WARNING: Killing these runaway processes at user's request (--force):
{PS-HEADER}
{PS-STATS} sleep 2.5

Learn why they did not stop: http://pgctl.readthedocs.org/en/latest/user/quickstart.html#writing-playground-services

[pgctl] Stopped: sweet
''',
            0,
            norm=norm.pgctl,
        )
Example #22
0
    def it_fails_by_default(self):
        check_call(('pgctl', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl', 'stop'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, its status is ready (pid {PID}) {TIME} seconds
==> playground/sweet/log <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/sweet/log
[pgctl] ERROR: Some services failed to stop: sweet
''',
            1,
            norm=norm.pgctl,
        )
Example #23
0
    def it_fails_by_default(self):
        check_call(('pgctl', 'start'))
        assert_svstat('playground/sweet', state='up')
        assert_command(
            ('pgctl', 'stop'),
            '',
            '''\
[pgctl] Stopping: sweet
[pgctl] ERROR: service 'sweet' failed to stop after {TIME} seconds, its status is ready (pid {PID}) {TIME} seconds
==> playground/sweet/logs/current <==
{TIMESTAMP} sweet
{TIMESTAMP} sweet_error
[pgctl]
[pgctl] There might be useful information further up in the log; you can view it by running:
[pgctl]     less +G playground/sweet/logs/current
[pgctl] ERROR: Some services failed to stop: sweet
''',
            1,
            norm=norm.pgctl,
        )
Example #24
0
    def it_can_shut_down_successfully(self):
        # if we configure it to wait a bit longer, it works fine
        with open('playground/sweet/timeout-stop', 'w') as timeout:
            timeout.write('3')

        check_call(('pgctl-2015', 'start'))
        assert_svstat('playground/sweet', state='up')

        check_call(('pgctl-2015', 'restart'))
        assert_svstat('playground/sweet', state='up')

        check_call(('pgctl-2015', 'stop'))
        assert_svstat('playground/sweet', state=SvStat.UNSUPERVISED)
Example #25
0
    def it_can_shut_down_successfully(self):
        # if we configure it to wait a bit longer, it works fine
        with open('playground/sweet/timeout-stop', 'w') as timeout:
            timeout.write('3')

        check_call(('pgctl', 'start'))
        assert_svstat('playground/sweet', state='up')

        check_call(('pgctl', 'restart'))
        assert_svstat('playground/sweet', state='up')

        check_call(('pgctl', 'stop'))
        assert_svstat('playground/sweet', state=SvStat.UNSUPERVISED)
Example #26
0
def it_disables_polling_heartbeat():
    from mock import patch
    with patch.dict(os.environ, [('PGCTL_TIMEOUT', '5')]):
        proc = Popen(('pgctl-2015', 'debug', 'slow-startup'), stdin=open(os.devnull), stdout=PIPE, stderr=PIPE)

    from testing.assertions import wait_for
    wait_for(lambda: assert_svstat('playground/slow-startup', state='ready'))

    check_call(('pgctl-2015', 'stop'))
    stdout, stderr = proc.communicate()
    stdout, stderr = stdout.decode('UTF-8'), stderr.decode('UTF-8')

    assert stderr == '''\
[pgctl] Stopping: slow-startup
[pgctl] Stopped: slow-startup
pgctl-poll-ready: service's ready check succeeded
pgctl-poll-ready: heartbeat is disabled during debug -- quitting
'''
    assert stdout == ''
    assert proc.returncode == 0
Example #27
0
 def it_works_with_nothing_running(self, in_example_dir):
     assert_svstat('playground/greeter', state=SvStat.UNSUPERVISED)
     self.assert_works_interactively()
Example #28
0
    def it_first_stops_the_background_service_if_running(self, in_example_dir):
        check_call(('pgctl-2015', 'start', 'greeter'))
        assert_svstat('playground/greeter', state='up')

        self.assert_works_interactively()
Example #29
0
    def it_does_stop(self, in_example_dir):
        check_call(('pgctl-2015', 'start', 'sleep'))
        check_call(('pgctl-2015', 'stop', 'sleep'))

        assert_svstat('playground/sleep', state=SvStat.UNSUPERVISED)
Example #30
0
 def it_is_ready():
     assert_svstat('playground/unreliable', state='ready')
Example #31
0
 def it_is_ready():
     assert_svstat('playground/slow-startup', state='ready')
Example #32
0
    def it_starts_everything_with_no_arguments_no_config(self, in_example_dir, request):
        check_call(("pgctl-2015", "start"))

        assert_svstat("playground/sleep", state="up")
        assert_svstat("playground/tail", state="up")
Example #33
0
    def it_starts_everything_with_no_arguments_no_config(
            self, in_example_dir, request):
        check_call(('pgctl', 'start'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state='up')
Example #34
0
    def it_only_starts_the_indicated_services(self, in_example_dir, request):
        check_call(('pgctl', 'start', 'sleep'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state=SvStat.UNSUPERVISED)
Example #35
0
    def it_starts_multiple_services(self, in_example_dir, request):
        check_call(('pgctl', 'start', 'sleep', 'tail'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state='up')
Example #36
0
    def it_does_stop(self, in_example_dir):
        check_call(('pgctl', 'start', 'sleep'))
        check_call(('pgctl', 'stop', 'sleep'))

        assert_svstat('playground/sleep', state=SvStat.UNSUPERVISED)
Example #37
0
    def it_also_works_when_up(self, in_example_dir):
        check_call(('pgctl', 'start', 'sleep'))
        assert_svstat('playground/sleep', state='up')

        self.it_is_just_stop_then_start(in_example_dir)
Example #38
0
    def it_only_starts_the_indicated_services(self, in_example_dir, request):
        check_call(('pgctl-2015', 'start', 'sleep'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state=SvStat.UNSUPERVISED)
Example #39
0
def it_works_with_nothing_running():
    assert_svstat('playground/greeter', state=SvStat.UNSUPERVISED)
    assert_works_interactively()
Example #40
0
def it_works_with_nothing_running():
    assert_svstat('playground/greeter', state=SvStat.UNSUPERVISED)
    assert_works_interactively()
Example #41
0
    def it_first_stops_the_background_service_if_running(self, in_example_dir):
        check_call(('pgctl-2015', 'start', 'greeter'))
        assert_svstat('playground/greeter', state='up')

        self.assert_works_interactively()
Example #42
0
 def it_stopped():
     assert_svstat('playground/slow-startup', state=SvStat.UNSUPERVISED)
Example #43
0
    def it_also_works_when_up(self, in_example_dir):
        check_call(('pgctl-2015', 'start', 'sleep'))
        assert_svstat('playground/sleep', state='up')

        self.it_is_just_stop_then_start(in_example_dir)
Example #44
0
 def it_works_with_nothing_running(self, in_example_dir):
     assert_svstat('playground/greeter', state=SvStat.UNSUPERVISED)
     self.assert_works_interactively()
Example #45
0
    def it_starts_multiple_services(self, in_example_dir, request):
        check_call(('pgctl-2015', 'start', 'sleep', 'tail'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state='up')
Example #46
0
    def it_also_works_when_up(self, in_example_dir):
        check_call(("pgctl-2015", "start", "sleep"))
        assert_svstat("playground/sleep", state="up")

        self.it_is_just_stop_then_start(in_example_dir)
Example #47
0
    def it_starts_everything_with_no_arguments_no_config(self, in_example_dir, request):
        check_call(('pgctl-2015', 'start'))

        assert_svstat('playground/sleep', state='up')
        assert_svstat('playground/tail', state='up')
Example #48
0
    def it_only_starts_the_indicated_services(self, in_example_dir, request):
        check_call(("pgctl-2015", "start", "sleep"))

        assert_svstat("playground/sleep", state="up")
        assert_svstat("playground/tail", state=SvStat.UNSUPERVISED)
Example #49
0
def it_first_stops_the_background_service_if_running():
    check_call(('pgctl', 'start', 'greeter'))
    assert_svstat('playground/greeter', state='up')

    assert_works_interactively()
Example #50
0
    def it_starts_multiple_services(self, in_example_dir, request):
        check_call(("pgctl-2015", "start", "sleep", "tail"))

        assert_svstat("playground/sleep", state="up")
        assert_svstat("playground/tail", state="up")