bookie_accounting 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -0
- data/Rakefile +4 -7
- data/TODO +1 -0
- data/bin/bookie-create-tables +1 -1
- data/bin/bookie-send +10 -1
- data/bookie_accounting.gemspec +6 -3
- data/lib/bookie/database.rb +241 -175
- data/lib/bookie/extensions.rb +72 -0
- data/lib/bookie/formatter.rb +15 -7
- data/lib/bookie/formatters/comma_dump.rb +9 -3
- data/lib/bookie/formatters/stdout.rb +1 -1
- data/lib/bookie/sender.rb +76 -16
- data/lib/bookie/senders/standalone.rb +2 -2
- data/lib/bookie/version.rb +1 -1
- data/rpm/bookie_accounting.spec.erb +2 -0
- data/spec/comma_dump_formatter_spec.rb +21 -12
- data/spec/database_spec.rb +199 -103
- data/spec/extensions_spec.rb +25 -0
- data/spec/formatter_spec.rb +37 -32
- data/spec/sender_spec.rb +127 -68
- data/spec/spec_helper.rb +15 -1
- data/spec/spreadsheet_formatter_spec.rb +16 -14
- data/spec/stdout_formatter_spec.rb +10 -8
- metadata +57 -11
data/spec/database_spec.rb
CHANGED
@@ -19,20 +19,32 @@ module Helpers
|
|
19
19
|
summaries
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def test_job_relations(job, relations)
|
23
|
+
#Make sure all relations with the same value have the same object_id:
|
23
24
|
rels = [job.user, job.user.group, job.system, job.system.system_type]
|
25
|
+
unbound_object_id = Object.instance_method(:object_id)
|
24
26
|
rels.each do |r|
|
25
27
|
if relations.include?(r)
|
26
|
-
|
27
|
-
|
28
|
+
relations[r].should eql unbound_object_id.bind(r).call
|
29
|
+
else
|
30
|
+
relations[r] = unbound_object_id.bind(r).call
|
28
31
|
end
|
29
|
-
relations[r] = r
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
35
|
+
def test_system_relations(system, relations)
|
36
|
+
t = system.system_type
|
37
|
+
unbound_object_id = Object.instance_method(:object_id)
|
38
|
+
if relations.include?(t)
|
39
|
+
relations[t].should eql unbound_object_id.bind(t).call
|
40
|
+
else
|
41
|
+
relations[t] = unbound_object_id.bind(t).call
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
32
45
|
|
33
46
|
def check_job_sums(js_sum, j_sum)
|
34
|
-
|
35
|
-
[:cpu_time, :memory_time, :successful].each do |field|
|
47
|
+
[:cpu_time, :memory_time].each do |field|
|
36
48
|
js_sum[field].should eql j_sum[field]
|
37
49
|
end
|
38
50
|
true
|
@@ -94,7 +106,6 @@ describe Bookie::Database do
|
|
94
106
|
describe Bookie::Database::Job do
|
95
107
|
before(:each) do
|
96
108
|
@jobs = Bookie::Database::Job
|
97
|
-
@base_time = @jobs.first.start_time
|
98
109
|
end
|
99
110
|
|
100
111
|
it "correctly sets end times" do
|
@@ -184,18 +195,18 @@ describe Bookie::Database do
|
|
184
195
|
end
|
185
196
|
|
186
197
|
it "correctly filters by start time" do
|
187
|
-
jobs = @jobs.by_start_time_range(
|
198
|
+
jobs = @jobs.by_start_time_range(base_time ... base_time + 3600 * 2 + 1)
|
188
199
|
jobs.length.should eql 3
|
189
|
-
jobs = @jobs.by_start_time_range(
|
200
|
+
jobs = @jobs.by_start_time_range(base_time + 1 ... base_time + 3600 * 2)
|
190
201
|
jobs.length.should eql 1
|
191
202
|
jobs = @jobs.by_start_time_range(Time.at(0) ... Time.at(3))
|
192
203
|
jobs.length.should eql 0
|
193
204
|
end
|
194
205
|
|
195
206
|
it "correctly filters by end time" do
|
196
|
-
jobs = @jobs.by_end_time_range(
|
207
|
+
jobs = @jobs.by_end_time_range(base_time ... base_time + 3600 * 2 + 1)
|
197
208
|
jobs.length.should eql 2
|
198
|
-
jobs = @jobs.by_end_time_range(
|
209
|
+
jobs = @jobs.by_end_time_range(base_time + 1 ... base_time + 3600 * 2)
|
199
210
|
jobs.length.should eql 1
|
200
211
|
jobs = @jobs.by_end_time_range(Time.at(0) ... Time.at(3))
|
201
212
|
jobs.length.should eql 0
|
@@ -203,24 +214,30 @@ describe Bookie::Database do
|
|
203
214
|
|
204
215
|
describe "#by_time_range_inclusive" do
|
205
216
|
it "correctly filters by inclusive time range" do
|
206
|
-
jobs = @jobs.by_time_range_inclusive(
|
207
|
-
jobs.
|
208
|
-
jobs = @jobs.by_time_range_inclusive(
|
209
|
-
jobs.
|
210
|
-
jobs = @jobs.by_time_range_inclusive(
|
217
|
+
jobs = @jobs.by_time_range_inclusive(base_time ... base_time + 3600 * 2 + 1)
|
218
|
+
jobs.count.should eql 3
|
219
|
+
jobs = @jobs.by_time_range_inclusive(base_time + 1 ... base_time + 3600 * 2)
|
220
|
+
jobs.count.should eql 2
|
221
|
+
jobs = @jobs.by_time_range_inclusive(base_time ... base_time)
|
211
222
|
jobs.length.should eql 0
|
223
|
+
jobs = @jobs.by_time_range_inclusive(base_time .. base_time + 3600 * 2)
|
224
|
+
jobs.count.should eql 3
|
225
|
+
jobs = @jobs.by_time_range_inclusive(base_time .. base_time)
|
226
|
+
jobs.count.should eql 1
|
212
227
|
end
|
213
228
|
|
214
|
-
it "correctly handles inverted ranges" do
|
215
|
-
t =
|
216
|
-
|
217
|
-
|
229
|
+
it "correctly handles empty/inverted ranges" do
|
230
|
+
t = base_time
|
231
|
+
(-1 .. 0).each do |offset|
|
232
|
+
jobs = @jobs.by_time_range_inclusive(t ... t + offset)
|
233
|
+
jobs.count.should eql 0
|
234
|
+
end
|
218
235
|
end
|
219
236
|
end
|
220
237
|
|
221
238
|
it "correctly chains filters" do
|
222
239
|
jobs = @jobs.by_user_name("test")
|
223
|
-
jobs = jobs.by_start_time_range(
|
240
|
+
jobs = jobs.by_start_time_range(base_time + 3600 ... base_time + 3601)
|
224
241
|
jobs.length.should eql 1
|
225
242
|
jobs[0].user.group.name.should eql "default"
|
226
243
|
end
|
@@ -229,19 +246,23 @@ describe Bookie::Database do
|
|
229
246
|
it "loads all relations" do
|
230
247
|
jobs = Bookie::Database::Job.limit(5)
|
231
248
|
relations = {}
|
232
|
-
jobs.all_with_relations
|
233
|
-
|
249
|
+
jobs = jobs.all_with_relations
|
250
|
+
Bookie::Database::User.expects(:new).never
|
251
|
+
Bookie::Database::Group.expects(:new).never
|
252
|
+
Bookie::Database::System.expects(:new).never
|
253
|
+
Bookie::Database::SystemType.expects(:new).never
|
254
|
+
jobs.each do |job|
|
255
|
+
test_job_relations(job, relations)
|
234
256
|
end
|
235
257
|
end
|
236
258
|
end
|
237
259
|
|
238
260
|
describe "#summary" do
|
239
261
|
before(:all) do
|
240
|
-
Time.expects(:now).returns(
|
241
|
-
@base_time = Time.local(2012)
|
262
|
+
Time.expects(:now).returns(base_time + 36000 * 4).at_least_once
|
242
263
|
@jobs = Bookie::Database::Job
|
243
264
|
@length = @jobs.all.length
|
244
|
-
@summary = Helpers::create_summaries(@jobs,
|
265
|
+
@summary = Helpers::create_summaries(@jobs, base_time)
|
245
266
|
end
|
246
267
|
|
247
268
|
it "produces correct summary totals" do
|
@@ -259,8 +280,7 @@ describe Bookie::Database do
|
|
259
280
|
clipped_jobs.should eql 25
|
260
281
|
@summary[:clipped][:cpu_time].should eql clipped_jobs * 100 - 50
|
261
282
|
@summary[:clipped][:memory_time].should eql clipped_jobs * 200 * 3600 - 100 * 3600
|
262
|
-
|
263
|
-
@summary[:clipped][:successful].should eql clipped_jobs / 2
|
283
|
+
@summary[:clipped][:successful].should eql clipped_jobs / 2 + 1
|
264
284
|
end
|
265
285
|
|
266
286
|
it "correctly handles summaries of empty sets" do
|
@@ -285,29 +305,17 @@ describe Bookie::Database do
|
|
285
305
|
end
|
286
306
|
end
|
287
307
|
|
288
|
-
it "only considers finished jobs to be successful" do
|
289
|
-
begin
|
290
|
-
job = Bookie::Database::Job.create!(
|
291
|
-
:user => Bookie::Database::User.first,
|
292
|
-
:system => Bookie::Database::System.first,
|
293
|
-
:command_name => '',
|
294
|
-
:cpu_time => 100,
|
295
|
-
:start_time => Time.local(2013),
|
296
|
-
:wall_time => 3600 * 24 * 2,
|
297
|
-
:memory => 10000,
|
298
|
-
:exit_code => 0
|
299
|
-
)
|
300
|
-
@jobs.summary(job.start_time ... job.start_time + 3600 * 24)[:successful].should eql 0
|
301
|
-
ensure
|
302
|
-
job.delete if job
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
|
307
308
|
it "correctly handles inverted ranges" do
|
308
309
|
@jobs.summary(Time.now() ... Time.now() - 1).should eql @summary[:empty]
|
309
310
|
@jobs.summary(Time.now() .. Time.now() - 1).should eql @summary[:empty]
|
310
311
|
end
|
312
|
+
|
313
|
+
it "distinguishes between inclusive and exclusive ranges" do
|
314
|
+
sum = @jobs.summary(base_time ... base_time + 3600)
|
315
|
+
sum[:jobs].length.should eql 1
|
316
|
+
sum = @jobs.summary(base_time .. base_time + 3600)
|
317
|
+
sum[:jobs].length.should eql 2
|
318
|
+
end
|
311
319
|
end
|
312
320
|
|
313
321
|
it "validates fields" do
|
@@ -316,7 +324,7 @@ describe Bookie::Database do
|
|
316
324
|
:system => Bookie::Database::System.first,
|
317
325
|
:command_name => '',
|
318
326
|
:cpu_time => 100,
|
319
|
-
:start_time =>
|
327
|
+
:start_time => base_time,
|
320
328
|
:wall_time => 1000,
|
321
329
|
:memory => 10000,
|
322
330
|
:exit_code => 0
|
@@ -356,7 +364,6 @@ describe Bookie::Database do
|
|
356
364
|
:system => system,
|
357
365
|
:command_name => command_name,
|
358
366
|
:date => date,
|
359
|
-
:num_jobs => 0,
|
360
367
|
:cpu_time => 0,
|
361
368
|
:memory_time => 0,
|
362
369
|
:successful => 0
|
@@ -375,6 +382,16 @@ describe Bookie::Database do
|
|
375
382
|
sum.date.should eql d
|
376
383
|
end
|
377
384
|
end
|
385
|
+
|
386
|
+
it "correctly filters by date range" do
|
387
|
+
d = Date.new(2012)
|
388
|
+
sums = Bookie::Database::JobSummary
|
389
|
+
sums.by_date_range(d .. d).count.should eql sums.by_date(d).count
|
390
|
+
sums.by_date_range(d ... d).count.should eql 0
|
391
|
+
sums.by_date_range(d + 1 .. d).count.should eql 0
|
392
|
+
sums.by_date_range(d .. d + 1).count.should eql sums.by_date(d).count + sums.by_date(d + 1).count
|
393
|
+
sums.by_date_range(d ... d + 1).count.should eql sums.by_date(d).count
|
394
|
+
end
|
378
395
|
|
379
396
|
it "correctly filters by user" do
|
380
397
|
u = Bookie::Database::User.first
|
@@ -450,14 +467,13 @@ describe Bookie::Database do
|
|
450
467
|
Bookie::Database::JobSummary.delete_all
|
451
468
|
s = Bookie::Database::JobSummary.find_or_new(Date.new(2012), 1, 1, 'vi')
|
452
469
|
s.persisted?.should eql false
|
453
|
-
s.num_jobs = 0
|
454
470
|
s.cpu_time = 0
|
455
471
|
s.memory_time = 0
|
456
|
-
s.successful = 0
|
457
472
|
s.save!
|
458
473
|
end
|
459
474
|
|
460
475
|
it "uses the old summary if present" do
|
476
|
+
#Uses the JobSummary created in the previous test
|
461
477
|
s = Bookie::Database::JobSummary.find_or_new(Date.new(2012), 1, 1, 'vi')
|
462
478
|
s.persisted?.should eql true
|
463
479
|
end
|
@@ -470,7 +486,7 @@ describe Bookie::Database do
|
|
470
486
|
|
471
487
|
it "produces correct summaries" do
|
472
488
|
d = Date.new(2012)
|
473
|
-
range =
|
489
|
+
range = base_time ... base_time + 1.days
|
474
490
|
Bookie::Database::JobSummary.summarize(d)
|
475
491
|
sums = Bookie::Database::JobSummary.all
|
476
492
|
found_sums = Set.new
|
@@ -481,74 +497,106 @@ describe Bookie::Database do
|
|
481
497
|
check_job_sums(sum, sum_2)
|
482
498
|
found_sums.add([sum.user.id, sum.system.id, sum.command_name])
|
483
499
|
end
|
484
|
-
#Is it
|
500
|
+
#Is it catching all of the combinations of categories?
|
485
501
|
Bookie::Database::Job.by_time_range_inclusive(range).select('user_id, system_id, command_name').uniq.all.each do |values|
|
486
502
|
values = [values.user_id, values.system_id, values.command_name]
|
487
503
|
found_sums.include?(values).should eql true
|
488
504
|
end
|
489
505
|
end
|
506
|
+
|
507
|
+
it "creates dummy summaries when there are no jobs" do
|
508
|
+
d = Date.new(2012) + 5
|
509
|
+
Bookie::Database::JobSummary.summarize(d)
|
510
|
+
sums = Bookie::Database::JobSummary.by_date(d).all
|
511
|
+
sums.length.should eql 1
|
512
|
+
sum = sums[0]
|
513
|
+
sum.cpu_time.should eql 0
|
514
|
+
sum.memory_time.should eql 0
|
515
|
+
|
516
|
+
#Check the case where there are no users or no systems:
|
517
|
+
Bookie::Database::JobSummary.delete_all
|
518
|
+
[Bookie::Database::User, Bookie::Database::System].each do |klass|
|
519
|
+
#This will cause nested transactions, but we *should* be OK.
|
520
|
+
Bookie::Database::JobSummary.transaction do
|
521
|
+
klass.delete_all
|
522
|
+
Bookie::Database::JobSummary.summarize(d)
|
523
|
+
Bookie::Database::JobSummary.by_date(d).count.should eql 0
|
524
|
+
raise ActiveRecord::Rollback
|
525
|
+
end
|
526
|
+
end
|
527
|
+
end
|
490
528
|
end
|
491
529
|
|
492
530
|
describe "#summary" do
|
493
531
|
before(:each) do
|
494
532
|
Bookie::Database::JobSummary.delete_all
|
495
|
-
t =
|
533
|
+
t = base_time + 2.days
|
496
534
|
Time.expects(:now).at_least(0).returns(t)
|
497
535
|
end
|
498
536
|
|
499
|
-
#To do: test inclusive ranges?
|
500
537
|
it "produces correct summaries" do
|
501
538
|
#To consider: flesh out some more?
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
while
|
506
|
-
while
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
539
|
+
time_start = base_time
|
540
|
+
time_end = time_start
|
541
|
+
time_bound = time_start + 3.days
|
542
|
+
while time_start < time_bound
|
543
|
+
while time_end < time_bound
|
544
|
+
[true, false].each do |exclude_end|
|
545
|
+
time_range = Range.new(time_start, time_end, exclude_end)
|
546
|
+
sum1 = Bookie::Database::JobSummary.summary(:range => time_range)
|
547
|
+
sum2 = Bookie::Database::Job.summary(time_range)
|
548
|
+
check_job_sums(sum1, sum2)
|
549
|
+
end
|
550
|
+
time_end += 1.days
|
514
551
|
end
|
515
|
-
|
552
|
+
time_start += 1.days
|
516
553
|
end
|
517
|
-
|
518
|
-
|
519
|
-
time_end = (date_start + 1).to_time
|
554
|
+
time_start = base_time
|
555
|
+
time_end = time_start + 1.days
|
520
556
|
[0, -7200, 7200].each do |offset_begin|
|
521
557
|
[0, -7200, 7200].each do |offset_end|
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
558
|
+
[true, false].each do |exclude_end|
|
559
|
+
range_offset = Range.new(time_start + offset_end, time_end + offset_end, exclude_end)
|
560
|
+
sum1 = Bookie::Database::JobSummary.summary(:range => range_offset)
|
561
|
+
sum2 = Bookie::Database::Job.summary(range_offset)
|
562
|
+
check_job_sums(sum1, sum2)
|
563
|
+
end
|
526
564
|
end
|
527
565
|
end
|
528
566
|
end
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
567
|
+
|
568
|
+
it "distinguishes between inclusive and exclusive ranges" do
|
569
|
+
Summary = Bookie::Database::JobSummary
|
570
|
+
sum = Summary.summary(:range => (base_time ... base_time + 3600 * 2))
|
571
|
+
sum[:num_jobs].should eql 2
|
572
|
+
sum = Summary.summary(:range => (base_time .. base_time + 3600 * 2))
|
573
|
+
sum[:num_jobs].should eql 3
|
574
|
+
end
|
575
|
+
|
576
|
+
def check_time_bounds(time_max = base_time + 1.days)
|
577
|
+
time_min = base_time
|
533
578
|
check_job_sums(Bookie::Database::JobSummary.summary, Bookie::Database::Job.summary)
|
534
|
-
Bookie::Database::JobSummary.order(:date).first.date.should eql
|
535
|
-
Bookie::Database::JobSummary.order('date DESC').first.date.should eql
|
579
|
+
Bookie::Database::JobSummary.order(:date).first.date.should eql time_min.to_date
|
580
|
+
Bookie::Database::JobSummary.order('date DESC').first.date.should eql time_max.utc.to_date
|
536
581
|
end
|
537
582
|
|
538
583
|
it "correctly finds the default time bounds" do
|
584
|
+
#The last daily summary in this range isn't cached because Time.now could be partway through a day.
|
539
585
|
check_time_bounds
|
540
586
|
systems = Bookie::Database::System.active_systems
|
541
587
|
Bookie::Database::JobSummary.delete_all
|
542
588
|
#Check the case where all systems are decommissioned.
|
589
|
+
end_times = {}
|
543
590
|
begin
|
544
591
|
systems.each do |sys|
|
545
|
-
sys.
|
592
|
+
end_times[sys.id] = sys.end_time
|
593
|
+
sys.end_time = base_time + 2.days
|
546
594
|
sys.save!
|
547
595
|
end
|
548
596
|
check_time_bounds
|
549
597
|
ensure
|
550
598
|
systems.each do |sys|
|
551
|
-
sys.end_time =
|
599
|
+
sys.end_time = end_times[sys.id]
|
552
600
|
sys.save!
|
553
601
|
end
|
554
602
|
end
|
@@ -570,8 +618,8 @@ describe Bookie::Database do
|
|
570
618
|
|
571
619
|
it "correctly handles filtered summaries" do
|
572
620
|
filters = {
|
573
|
-
:user_name => '
|
574
|
-
:group_name => '
|
621
|
+
:user_name => 'test',
|
622
|
+
:group_name => 'admin',
|
575
623
|
:command_name => 'vi',
|
576
624
|
}
|
577
625
|
filters.each do |filter, value|
|
@@ -584,7 +632,7 @@ describe Bookie::Database do
|
|
584
632
|
end
|
585
633
|
|
586
634
|
it "correctly handles inverted ranges" do
|
587
|
-
t =
|
635
|
+
t = base_time
|
588
636
|
Bookie::Database::JobSummary.summary(:range => t .. t - 1).should eql({
|
589
637
|
:num_jobs => 0,
|
590
638
|
:cpu_time => 0,
|
@@ -594,9 +642,16 @@ describe Bookie::Database do
|
|
594
642
|
end
|
595
643
|
|
596
644
|
it "caches summaries" do
|
645
|
+
Bookie::Database::JobSummary.summary
|
646
|
+
Bookie::Database::JobSummary.expects(:summarize).never
|
647
|
+
range = base_time ... base_time + 1.days
|
648
|
+
Bookie::Database::JobSummary.summary(:range => range)
|
649
|
+
end
|
650
|
+
|
651
|
+
it "uses the cached summaries" do
|
597
652
|
Bookie::Database::JobSummary.summary
|
598
653
|
Bookie::Database::Job.expects(:summary).never
|
599
|
-
range =
|
654
|
+
range = base_time ... base_time + 1.days
|
600
655
|
Bookie::Database::JobSummary.summary(:range => range)
|
601
656
|
end
|
602
657
|
end
|
@@ -607,12 +662,10 @@ describe Bookie::Database do
|
|
607
662
|
:system => Bookie::Database::System.first,
|
608
663
|
:command_name => '',
|
609
664
|
:date => Date.new(2012),
|
610
|
-
:num_jobs => 1,
|
611
665
|
:cpu_time => 100,
|
612
666
|
:memory_time => 1000000,
|
613
|
-
:successful => 1,
|
614
667
|
}
|
615
|
-
|
668
|
+
|
616
669
|
sum = Bookie::Database::JobSummary.new(fields)
|
617
670
|
sum.valid?.should eql true
|
618
671
|
|
@@ -622,7 +675,7 @@ describe Bookie::Database do
|
|
622
675
|
job.valid?.should eql false
|
623
676
|
end
|
624
677
|
|
625
|
-
[:cpu_time, :memory_time
|
678
|
+
[:cpu_time, :memory_time].each do |field|
|
626
679
|
job = Bookie::Database::JobSummary.new(fields)
|
627
680
|
m = job.method("#{field}=".intern)
|
628
681
|
m.call(-1)
|
@@ -725,6 +778,10 @@ describe Bookie::Database do
|
|
725
778
|
end
|
726
779
|
|
727
780
|
describe Bookie::Database::System do
|
781
|
+
before(:each) do
|
782
|
+
@systems = Bookie::Database::System
|
783
|
+
end
|
784
|
+
|
728
785
|
it "correctly finds active systems" do
|
729
786
|
Bookie::Database::System.active_systems.length.should eql 3
|
730
787
|
end
|
@@ -741,14 +798,47 @@ describe Bookie::Database do
|
|
741
798
|
Bookie::Database::System.by_system_type(t).length.should eql 2
|
742
799
|
end
|
743
800
|
end
|
744
|
-
|
801
|
+
|
802
|
+
describe "#all_with_relations" do
|
803
|
+
it "loads all relations" do
|
804
|
+
systems = Bookie::Database::System.limit(5)
|
805
|
+
relations = {}
|
806
|
+
systems = systems.all_with_relations
|
807
|
+
Bookie::Database::SystemType.expects(:new).never
|
808
|
+
systems.each do |system|
|
809
|
+
test_system_relations(system, relations)
|
810
|
+
end
|
811
|
+
end
|
812
|
+
end
|
813
|
+
|
814
|
+
describe "#by_time_range_inclusive" do
|
815
|
+
it "correctly filters by inclusive time range" do
|
816
|
+
systems = @systems.by_time_range_inclusive(base_time ... base_time + 36000 * 2 + 1)
|
817
|
+
systems.count.should eql 3
|
818
|
+
systems = @systems.by_time_range_inclusive(base_time + 1 ... base_time + 36000 * 2)
|
819
|
+
systems.count.should eql 2
|
820
|
+
systems = @systems.by_time_range_inclusive(base_time ... base_time)
|
821
|
+
systems.length.should eql 0
|
822
|
+
systems = @systems.by_time_range_inclusive(base_time .. base_time + 36000 * 2)
|
823
|
+
systems.count.should eql 3
|
824
|
+
systems = @systems.by_time_range_inclusive(base_time .. base_time)
|
825
|
+
systems.count.should eql 1
|
826
|
+
end
|
827
|
+
|
828
|
+
it "correctly handles empty/inverted ranges" do
|
829
|
+
(-1 .. 0).each do |offset|
|
830
|
+
systems = @systems.by_time_range_inclusive(base_time ... base_time + offset)
|
831
|
+
systems.count.should eql 0
|
832
|
+
end
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
745
836
|
describe "#summary" do
|
746
837
|
before(:all) do
|
747
|
-
Time.expects(:now).returns(
|
748
|
-
@base_time = Time.local(2012)
|
838
|
+
Time.expects(:now).returns(base_time + 3600 * 40).at_least_once
|
749
839
|
@systems = Bookie::Database::System
|
750
|
-
@summary = Helpers::create_summaries(@systems,
|
751
|
-
@summary_wide = @systems.summary(
|
840
|
+
@summary = Helpers::create_summaries(@systems, base_time)
|
841
|
+
@summary_wide = @systems.summary(base_time - 3600 ... base_time + 3600 * 40 + 3600)
|
752
842
|
end
|
753
843
|
|
754
844
|
it "produces correct summaries" do
|
@@ -761,18 +851,23 @@ describe Bookie::Database do
|
|
761
851
|
avg_mem = Float(1000000 * system_total_wall_time / (3600 * 40))
|
762
852
|
clipped_avg_mem = Float(1000000 * system_clipped_wall_time) / (3600 * 25 - 1800)
|
763
853
|
wide_avg_mem = Float(1000000 * system_wide_wall_time) / (3600 * 42)
|
854
|
+
@summary[:all][:systems].length.should eql 4
|
764
855
|
@summary[:all][:avail_cpu_time].should eql system_total_cpu_time
|
765
856
|
@summary[:all][:avail_memory_time].should eql 1000000 * system_total_wall_time
|
766
857
|
@summary[:all][:avail_memory_avg].should eql avg_mem
|
858
|
+
@summary[:all_constrained][:systems].length.should eql 4
|
767
859
|
@summary[:all_constrained][:avail_cpu_time].should eql system_total_cpu_time
|
768
860
|
@summary[:all_constrained][:avail_memory_time].should eql 1000000 * system_total_wall_time
|
769
861
|
@summary[:all_constrained][:avail_memory_avg].should eql avg_mem
|
862
|
+
@summary[:clipped][:systems].length.should eql 3
|
770
863
|
@summary[:clipped][:avail_cpu_time].should eql clipped_cpu_time
|
771
864
|
@summary[:clipped][:avail_memory_time].should eql system_clipped_wall_time * 1000000
|
772
865
|
@summary[:clipped][:avail_memory_avg].should eql clipped_avg_mem
|
866
|
+
@summary_wide[:systems].length.should eql 4
|
773
867
|
@summary_wide[:avail_cpu_time].should eql system_wide_cpu_time
|
774
868
|
@summary_wide[:avail_memory_time].should eql 1000000 * system_wide_wall_time
|
775
869
|
@summary_wide[:avail_memory_avg].should eql wide_avg_mem
|
870
|
+
@summary[:empty][:systems].length.should eql 0
|
776
871
|
@summary[:empty][:avail_cpu_time].should eql 0
|
777
872
|
@summary[:empty][:avail_memory_time].should eql 0
|
778
873
|
@summary[:empty][:avail_memory_avg].should eql 0.0
|
@@ -785,7 +880,7 @@ describe Bookie::Database do
|
|
785
880
|
end
|
786
881
|
summary_all_systems_ended = @systems.summary()
|
787
882
|
summary_all_systems_ended.should eql @summary[:all]
|
788
|
-
summary_all_systems_ended = @systems.summary(
|
883
|
+
summary_all_systems_ended = @systems.summary(base_time ... Time.now + 3600)
|
789
884
|
s2 = @summary[:all].dup
|
790
885
|
s2[:avail_memory_avg] = Float(1000000 * system_total_wall_time) / (3600 * 41)
|
791
886
|
summary_all_systems_ended.should eql s2
|
@@ -800,7 +895,7 @@ describe Bookie::Database do
|
|
800
895
|
end
|
801
896
|
|
802
897
|
it "correctly handles inverted ranges" do
|
803
|
-
t =
|
898
|
+
t = base_time
|
804
899
|
@systems.summary(t ... t - 1).should eql @summary[:empty]
|
805
900
|
@systems.summary(t .. t - 1).should eql @summary[:empty]
|
806
901
|
end
|
@@ -825,16 +920,16 @@ describe Bookie::Database do
|
|
825
920
|
it "finds the correct system" do
|
826
921
|
Bookie::Database::System.find_current(@sender_2).id.should eql 2
|
827
922
|
Bookie::Database::System.find_current(@sender_2, Time.now).id.should eql 2
|
828
|
-
Bookie::Database::System.find_current(@sender_1,
|
923
|
+
Bookie::Database::System.find_current(@sender_1, base_time).id.should eql 1
|
829
924
|
end
|
830
925
|
|
831
926
|
it "correctly detects the lack of a matching system" do
|
832
927
|
expect {
|
833
|
-
Bookie::Database::System.find_current(@sender_1,
|
928
|
+
Bookie::Database::System.find_current(@sender_1, base_time - 1.years)
|
834
929
|
}.to raise_error(/^There is no system with hostname 'test1' in the database at /)
|
835
930
|
@config_t1.expects(:hostname).at_least_once.returns('test1000')
|
836
931
|
expect {
|
837
|
-
Bookie::Database::System.find_current(@sender_1,
|
932
|
+
Bookie::Database::System.find_current(@sender_1, base_time)
|
838
933
|
}.to raise_error(/^There is no system with hostname 'test1000' in the database at /)
|
839
934
|
end
|
840
935
|
|
@@ -876,7 +971,7 @@ describe Bookie::Database do
|
|
876
971
|
:cores => 2,
|
877
972
|
:memory => 1000000,
|
878
973
|
:system_type => Bookie::Database::SystemType.first,
|
879
|
-
:start_time =>
|
974
|
+
:start_time => base_time
|
880
975
|
}
|
881
976
|
|
882
977
|
Bookie::Database::System.new(fields).valid?.should eql true
|
@@ -901,7 +996,7 @@ describe Bookie::Database do
|
|
901
996
|
end
|
902
997
|
|
903
998
|
system = Bookie::Database::System.new(fields)
|
904
|
-
system.end_time =
|
999
|
+
system.end_time = base_time
|
905
1000
|
system.valid?.should eql true
|
906
1001
|
system.end_time += 5
|
907
1002
|
system.valid?.should eql true
|
@@ -970,3 +1065,4 @@ describe Bookie::Database do
|
|
970
1065
|
end
|
971
1066
|
end
|
972
1067
|
end
|
1068
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Range do
|
4
|
+
describe "#normalized" do
|
5
|
+
it "correctly normalizes" do
|
6
|
+
(1 .. 2).normalized.should eql(1 .. 2)
|
7
|
+
(1 .. 1).normalized.should eql(1 .. 1)
|
8
|
+
(1 ... 1).normalized.should eql(1 ... 1)
|
9
|
+
(1 .. 0).normalized.should eql(1 ... 1)
|
10
|
+
(1 ... 0).normalized.should eql( 1 ... 1 )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "empty?" do
|
15
|
+
it "correctly determines emptiness" do
|
16
|
+
(1 .. 2).empty?.should eql false
|
17
|
+
(1 .. 1).empty?.should eql false
|
18
|
+
(1 ... 2).empty?.should eql false
|
19
|
+
(1 ... 1).empty?.should eql true
|
20
|
+
(1 .. 0).empty?.should eql true
|
21
|
+
(1 ... 0).empty?.should eql true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|