forked from caidongyun/beanstalkd-win
-
Notifications
You must be signed in to change notification settings - Fork 6
/
testjobs.c
139 lines (107 loc) · 2.87 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
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "ct/ct.h"
#include "dat.h"
static tube default_tube;
void
cttestjob_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
cttestjob_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
cttestjob_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
cttestjob_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
cttestjob_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
cttestjob_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
cttestjob_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
cttestjob_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
ctbenchmakejob(int n)
{
int i;
TUBE_ASSIGN(default_tube, make_tube("default"));
for (i = 0; i < n; i++) {
make_job(0, 0, 1, 0, default_tube);
}
}