11.exp 3.83 KB
Newer Older
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
# Test suite for lyskomd.
# Copyright (C) 1999  Lysator Academic Computer Association.
#
# This file is part of the LysKOM server.
# 
# LysKOM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by 
# the Free Software Foundation; either version 1, or (at your option) 
# any later version.
# 
# LysKOM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License
# along with LysKOM; see the file COPYING.  If not, write to
# Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
# or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
# MA 02139, USA.
#
# Please mail bug reports to bug-lyskom@lysator.liu.se. 

# Test the lock file of lyskomd and dbck.

# Start a server that locks the database.
lyskomd_start

# Start dbck in read-only mode.  No lock is required.
spawn ../dbck -d config/lyskomd-config
set test "dbck started in read-only mode"
expect {
    -re "^MSG: init_cache: using datafile\.$nl" { pass "$test" }
}
set test "read-only dbck sent second line"
expect {
    -re "^Read $any_num confs/persons and $any_num texts, eof at $any_num$nl" {
	pass "$test"
    }
}
set test "read-only dbck sent final line"
expect {
    -re "^Press enter to terminate dbck$nl" {
	pass "$test"
    }
}
send "\n"
set test "read-only dbck died"
expect {
50
    eof { pass "$test"; wait }
51 52 53 54 55 56 57
}
unset test

# Attempt to start dbck in read-write mode.
spawn ../dbck -d -i config/lyskomd-config
set test "dbck finds a lock"
expect {
58
    -re "^Database already locked by $any*\.$nl" { pass "$test" }
59 60 61 62 63 64 65 66 67 68
}
set test "read-write dbck sent final line"
expect {
    -re "^Press enter to terminate dbck$nl" {
	pass "$test"
    }
}
send "\n"
set test "read-write dbck died"
expect {
69
    eof { pass "$test"; wait }
70 71 72 73 74 75 76
}
unset test

# Attempt to start a second lyskomd.
spawn ../lyskomd -d config/lyskomd-config
set test "lyskomd finds a lock"
expect {
77 78 79 80 81
    -re "Database already locked by $any*:$lyskomd_pid$nl" { pass "$test" }
}
set test "lyskomd writes an exiting message."
expect {
    -re "Cannot obtain database lock\.  Exiting\.$nl" { pass "$test" }
82 83 84 85 86 87 88 89 90 91
}
set test "read-write lyskomd sent final line"
expect {
    -re "^\[0-9 :\]* Press enter to terminate lyskomd$nl" {
	pass "$test"
    }
}
send "\n"
set test "read-write lyskomd died"
expect {
92
    eof { pass "$test"; wait }
93 94 95 96 97 98 99 100 101 102 103 104 105 106
}
unset test

# Shut down lyskomd.
system "kill -HUP $lyskomd_pid"
lyskomd_death

# Start a new lyskomd.
lyskomd_start

# Kill it so that it cannot remove the lock file.
system "kill -KILL $lyskomd_pid"
set test "lyskomd was killed"
expect {
107
    eof { pass "$test"; wait }
108 109 110 111 112 113
}

# Start a new lyskomd.  Check that it removes the stale lock file.
set new_pid [spawn ../lyskomd -d config/lyskomd-config]
set test "stale lock file removed"
expect {
114
    -re " $new_pid Removed stale lock file left by $any*:$lyskomd_pid\.$nl" {
115 116 117 118
	pass "$test"
    }
}

119
system "kill -HUP $new_pid"
120 121
set test "non-stale lyskomd sent final line"
expect {
122
    -re "^\[0-9 :\]* $new_pid Press enter to terminate lyskomd$nl" {
123 124 125 126 127 128
	pass "$test"
    }
}
send "\n"
set test "non-stale lyskomd died"
expect {
129
    eof { pass "$test"; wait }
130 131 132
}
unset test

133 134 135 136 137
# Start a new lyskomd while a lock file for a remote system exists.
system "ln -s inet.lysator.liu.se:4711 db/lyskomd-lock"
spawn ../lyskomd -d config/lyskomd-config
set test "remote lock file found"
expect {
138
    -re "Database already locked by inet\.lysator\.liu\.se:4711$nl" {
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
	pass "$test"
    }
}
set test "local lyskomd sent final line"
expect {
    -re "^\[0-9 :\]* Press enter to terminate lyskomd$nl" {
	pass "$test"
    }
}
send "\n"
set test "local lyskomd died"
expect {
    eof { pass "$test"; wait }
}
unset test