summaryrefslogtreecommitdiff
path: root/cpp/demo/Freeze/backup/expect.py
blob: 98c530a84e8f9e4cd1e2ac046187098dbf1e847a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

import sys, os

try:
    import demoscript
except ImportError:
    for toplevel in [".", "..", "../..", "../../..", "../../../.."]:
        toplevel = os.path.normpath(toplevel)
        if os.path.exists(os.path.join(toplevel, "demoscript")):
            break
    else:
        raise "can't find toplevel directory!"
    sys.path.append(os.path.join(toplevel))
    import demoscript

import demoscript.Util
demoscript.Util.defaultLanguage = "C++"
import signal, time
import demoscript.pexpect as pexpect

print "cleaning databases...",
sys.stdout.flush()
os.system('rm -fr db.save')
demoscript.Util.cleanDbDir("db/data")
demoscript.Util.cleanDbDir("db/logs")
os.system('rm -fr db/__*')
for d in os.listdir('.'):
    if d.startswith('hotbackup'):
        os.system('rm -rf %s' % (d))
print "ok"

client = demoscript.Util.spawn('./client')

print "populating map...",
sys.stdout.flush()
client.expect('Updating map', timeout=60)
time.sleep(3) # Let the client do some work for a bit.
print "ok"


print "performing full backup...",
sys.stdout.flush()
backup = demoscript.Util.spawn('./backup full')
backup.expect('hot backup started', timeout=30)
backup.waitTestSuccess(timeout=30)
print "ok"

print "sleeping 5s...",
sys.stdout.flush()
time.sleep(5)
print "ok"

print "performing incremental backup...",
sys.stdout.flush()
backup = demoscript.Util.spawn('./backup incremental')
backup.expect('hot backup started', timeout=30)
backup.waitTestSuccess(timeout=30)
print "ok"

print "sleeping 30s...",
sys.stdout.flush()
time.sleep(30)
print "ok"

assert os.path.isdir('hotbackup')

print "killing client with SIGTERM...",
sys.stdout.flush()
client.kill(signal.SIGTERM)
client.expect(pexpect.EOF, timeout=30)
client.wait()
assert client.signalstatus == signal.SIGTERM
print "ok"

print "Client output: ",
print "%s " % (client.before)

print "restarting client...",
sys.stdout.flush()
os.system('rm -fr db/data/* db/logs/* db/__*')
os.system('cp -Rp hotbackup/* db')
sys.stdout.flush()

client = demoscript.Util.spawn('./client')
client.expect('(.*)Updating map', timeout=60)
assert client.match.group(1).find('Creating new map') == -1
print "ok"

print "sleeping 5s...",
sys.stdout.flush()
time.sleep(5)
print "ok"

print "killing client with SIGTERM...",
client.kill(signal.SIGTERM)
client.expect(pexpect.EOF, timeout=30)
client.wait()
assert client.signalstatus == signal.SIGTERM
print "ok"

print "Restarted client output:",
print "%s " % (client.before)