forked from beanstalkd/beanstalkd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testjobs.c
166 lines (130 loc) · 3.37 KB
/
testjobs.c
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "ct/ct.h"
#include "dat.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
static Tube *default_tube;
void
cttest_job_creation()
{
Job *j;
TUBE_ASSIGN(default_tube, make_tube("default"));
j = make_job(1, 0, 1, 0, default_tube);
assertf(j->r.pri == 1, "priority should match");
}
void
cttest_job_cmp_pris()
{
Job *a, *b;
TUBE_ASSIGN(default_tube, make_tube("default"));
a = make_job(1, 0, 1, 0, default_tube);
b = make_job(1 << 27, 0, 1, 0, default_tube);
assertf(job_pri_less(a, b), "should be less");
}
void
cttest_job_cmp_ids()
{
Job *a, *b;
TUBE_ASSIGN(default_tube, make_tube("default"));
a = make_job(1, 0, 1, 0, default_tube);
b = make_job(1, 0, 1, 0, default_tube);
b->r.id <<= 49;
assertf(job_pri_less(a, b), "should be less");
}
void
cttest_job_large_pris()
{
Job *a, *b;
TUBE_ASSIGN(default_tube, make_tube("default"));
a = make_job(1, 0, 1, 0, default_tube);
b = make_job(-5, 0, 1, 0, default_tube);
assertf(job_pri_less(a, b), "should be less");
a = make_job(-5, 0, 1, 0, default_tube);
b = make_job(1, 0, 1, 0, default_tube);
assertf(!job_pri_less(a, b), "should not be less");
}
void
cttest_job_hash_free()
{
Job *j;
uint64 jid = 83;
TUBE_ASSIGN(default_tube, make_tube("default"));
j = make_job_with_id(0, 0, 1, 0, default_tube, jid);
job_free(j);
assertf(!job_find(jid), "job should be missing");
}
void
cttest_job_hash_free_next()
{
Job *a, *b;
uint64 aid = 97, bid = 12386;
TUBE_ASSIGN(default_tube, make_tube("default"));
b = make_job_with_id(0, 0, 1, 0, default_tube, bid);
a = make_job_with_id(0, 0, 1, 0, default_tube, aid);
assertf(a->ht_next == b, "b should be chained to a");
job_free(b);
assertf(a->ht_next == NULL, "job should be missing");
}
void
cttest_job_all_jobs_used()
{
Job *j, *x;
TUBE_ASSIGN(default_tube, make_tube("default"));
j = make_job(0, 0, 1, 0, default_tube);
assertf(get_all_jobs_used() == 1, "should match");
x = allocate_job(10);
assertf(get_all_jobs_used() == 1, "should match");
job_free(x);
assertf(get_all_jobs_used() == 1, "should match");
job_free(j);
assertf(get_all_jobs_used() == 0, "should match");
}
void
cttest_job_100_000_jobs()
{
int i;
TUBE_ASSIGN(default_tube, make_tube("default"));
for (i = 0; i < 100000; i++) {
make_job(0, 0, 1, 0, default_tube);
}
assertf(get_all_jobs_used() == 100000, "should match");
for (i = 1; i <= 100000; i++) {
job_free(job_find(i));
}
fprintf(stderr, "get_all_jobs_used() => %zu\n", get_all_jobs_used());
assertf(get_all_jobs_used() == 0, "should match");
}
void
ctbench_job_make(int n)
{
int i;
Job **j = calloc(n, sizeof *j);
TUBE_ASSIGN(default_tube, make_tube("default"));
ctresettimer();
for (i = 0; i < n; i++) {
j[i] = make_job(0, 0, 1, 0, default_tube);
}
ctstoptimer();
for (i = 0; i < n; i++) {
job_free(j[i]);
}
free(j);
}
void
ctbench_job_free(int n)
{
int i;
Job **j = calloc(n, sizeof *j);
TUBE_ASSIGN(default_tube, make_tube("default"));
for (i = 0; i < n; i++) {
j[i] = make_job(0, 0, 1, 0, default_tube);
}
ctresettimer();
for (i = 0; i < n; i++) {
job_free(j[i]);
}
ctstoptimer();
free(j);
}