summaryrefslogtreecommitdiff
path: root/cpp/demo/Freeze/backup/expect.py
blob: a9fb31abb59dbad3dc924e1733180bf713a6c9b3 (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
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2009 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

path = [ ".", "..", "../..", "../../..", "../../../.." ]
head = os.path.dirname(sys.argv[0])
if len(head) > 0:
    path = [os.path.join(head, p) for p in path]
path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "demoscript")) ]
if len(path) == 0:
    raise "can't find toplevel directory!"
sys.path.append(path[0])

from demoscript import *
import shutil
import signal, time

def cleandb():
    shutil.rmtree("db.save", True)
    Util.cleanDbDir("db/data")
    Util.cleanDbDir("db/logs")
    for filename in [ os.path.join("db", f) for f in os.listdir("db") if f.startswith("__") ]:
        os.remove(filename)

print "cleaning databases...",
sys.stdout.flush()
cleandb()
for d in os.listdir('.'):
    if d.startswith('hotbackup'):
        shutil.rmtree(d)
print "ok"

client = 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()
if Util.isWin32():
    backup = Util.spawn('./backup.bat full')
else:
    backup = 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()
if Util.isWin32():
    backup = Util.spawn('./backup.bat incremental')
else:
    backup = 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.waitTestSuccess(-signal.SIGTERM)
print "ok"

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

print "restarting client...",
sys.stdout.flush()
cleandb()
# Annoying. shutil.copytree cannot be used since db already exists
# (and cannot be removed since it contains .gitignore.
#os.system('cp -Rp hotbackup/* db')
for root, dirnames, filesnames in os.walk("hotbackup"):
    dbroot = os.path.join("db", root[len("hotbackup")+1:])
    for d in dirnames:
        try:
            os.mkdir(os.path.join("db", d))
        except OSError:
            pass
    for f in filesnames:
        shutil.copy2(os.path.join(root, f), os.path.join(dbroot, f))
sys.stdout.flush()

client = 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.waitTestSuccess(-signal.SIGTERM)
print "ok"

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