-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
116 lines (92 loc) · 1.99 KB
/
test.pl
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
use strict;
my @test = (
0, # 1, load module
0, # 2, test default port
0, # 3, test configured port
0, # 4, test two different ports
0, # 5, test same ports for failure
);
my $test = @test;
print "1..".$test."\n";
our $loaded;
our $debug = 0;
BEGIN { $| = 1; }
END { print "not ok $test\n" unless $loaded; }
{
$test = 1;
$loaded = 0;
use JoeDog::Plock;
$loaded = 1;
print "ok $test\n";
}
{
$test = 2;
$loaded = 0;
use JoeDog::Plock;
my $lock = new JoeDog::Plock();
$lock->set_debug() if $debug;
if (! $lock->lock()) {
die("Port Already lock, please check if already running!\n");
}
$lock->unlock();
print "\n" if $test[1];
$loaded = 1;
print "ok $test\n";
}
{
$test = 3;
$loaded = 0;
use JoeDog::Plock;
my $lock = new JoeDog::Plock(55555);
$lock->set_debug() if $debug;
if (! $lock->lock()) {
die ("Port Already lock, please check if already running!\n");
}
$lock->unlock();
print "\n" if $test[1];
$loaded = 1;
print "ok $test\n";
}
{
$test = 4;
$loaded = 0;
my $lockA = new JoeDog::Plock(55555);
my $lockB = new JoeDog::Plock(55556);
$lockA->set_debug() if $debug;
$lockB->set_debug() if $debug;
if (! $lockA->lock()) {
die ("Port Already lock, please check if already running!\n");
}
if (! $lockB->lock()) {
die ("Port Already lock, please check if already running!\n");
}
$lockA->unlock();
$lockB->unlock();
print "\n" if $test[1];
$loaded = 1;
print "ok $test\n";
}
{
$test = 5;
my $okay = 0;
$loaded = 0;
my $lockA = new JoeDog::Plock(55555);
my $lockB = new JoeDog::Plock(55555);
$lockA->set_debug() if $debug;
$lockB->set_debug() if $debug;
if (! $lockA->lock()) {
die ("Port Already lock, please check if already running!\n");
}
if (! $lockB->lock()) {
$okay = 1;
}
$lockA->unlock();
$lockB->unlock();
print "\n" if $test[1];
$loaded = 1;
if ($okay) {
print "ok $test\n";
} else {
print "fail $test\n";
}
}