summaryrefslogtreecommitdiff
path: root/libmailutils/tests/lock.at
blob: 75fef24ddc72bf25595431df9372ad1f5fd891fd (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# This file is part of GNU Mailutils. -*- Autotest -*-
# Copyright (C) 2010-2021 Free Software Foundation, Inc.
#
# GNU Mailutils 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 3, or (at
# your option) any later version.
#
# GNU Mailutils 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 GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.

AT_BANNER([Locking])

m4_pushdef([LCK_TEST],[
AT_SETUP([$1])
AT_KEYWORDS([lock])
AT_CHECK([touch file
lck $2 file
],
m4_shift2($@))
AT_CLEANUP
])

# Child holds lock for 4 seconds, master acquires it when child has
# released it.
LCK_TEST([retries], [--hold=4 --retry=10 --delay=1])

# Child holds lock for 4 seconds, master does two retries with one
# second interval and finishes before being able to acquire it.
LCK_TEST([conflict with previous locker], [--hold=4 --retry=2 --delay=1],
         [3])

# Child abandons the lock; master is not able to acquire it.
LCK_TEST([abandoned lock], [--abandon --retry=4 --delay=1],
         [3])

# Child abandons the lock; master asserts that its pid is not active and
# acquires it.
LCK_TEST([PID check],[--pid-check --abandon --retry=4 --delay=1])

# Child abandons the lock; master waits until it has expired and acquires
# it.
LCK_TEST([lock expiration],
         [--abandon --expire=3 --retry=10 --delay=1])


# Default settings correspond to --retry=10 --delay=1 --expire=600
LCK_TEST([default settings], [--hold=2])

AT_SETUP([external locker])
AT_KEYWORDS([lock])

AT_DATA([extlocker],
[#!/bin/sh
echo "$@" > extlocker.args
])
CWD=$(pwd)

m4_pushdef([COND_SKIP],[test -f .skiptest && AT_SKIP_TEST])

AT_CHECK([
if chmod +x extlocker; then :; else touch .skiptest; fi >/dev/null 2>&1
COND_SKIP
],
[ignore])

AT_CHECK([COND_SKIP
lck -e$CWD/extlocker file
cat extlocker.args
],
[0],
[file
])

AT_CHECK([COND_SKIP
lck -e$CWD/extlocker --retry=4 --expire=35 file
cat extlocker.args
],
[0],
[-f35 -r4 file
])

AT_CHECK([COND_SKIP
touch file
lck -elck file
])

AT_CHECK([COND_SKIP
lck -elck file
],
[3])

AT_CHECK([COND_SKIP
lck -elck -u file
],
[0])

AT_CHECK([COND_SKIP
lck -elck -u file
],
[2])

# Child holds lock for 4 seconds, master acquires it when child has
# released it.
AT_CHECK([COND_SKIP
lck -elck --hold=4 --retry=10 --delay=1 file
])

AT_CHECK([COND_SKIP
lck -elck -u file
])

AT_CHECK([COND_SKIP
# Child holds lock for 4 seconds, master does two retries with one
# second interval and finishes before being able to acquire it.
lck -elck --hold=4 --retry=2 --delay=1 file
],
[3])

AT_CHECK([COND_SKIP
# Master is not able to acquire abandoned lock.
lck -elck --retry=4 --delay=1 file
],
[3])

AT_CHECK([COND_SKIP
# Master waits until lock has expired and acquires it.
lck -elck --abandon --expire=3 --retry=10 --delay=1 file
])

m4_popdef([COND_SKIP])
AT_CLEANUP

m4_popdef([LCK_TEST])

Return to:

Send suggestions and report system problems to the System administrator.