pseudo_cleaner 0.0.42 → 0.0.43
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.
- checksums.yaml +8 -8
- data/lib/pseudo_cleaner.rb +14 -9
- data/lib/pseudo_cleaner/configuration.rb +2 -0
- data/lib/pseudo_cleaner/master_cleaner.rb +135 -85
- data/lib/pseudo_cleaner/redis_cleaner.rb +92 -50
- data/lib/pseudo_cleaner/table_cleaner.rb +121 -61
- data/lib/pseudo_cleaner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDZkNTM0YTI5M2ZhMDk4NGNiMzc3Mzk2YmRiMTFhNmNkNDI4NmI1Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTU1ZDM0NzQxOTg4OTlkNDRkY2YzMWQ1NGQ2ZDhlOGI4NDBmMGI0MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGIyZTI0ODJjMmZiNjBiZDQyODcwMzU1MWI1Y2ZjNmViYjFlOWUzZTQ5Mjc3
|
10
|
+
ZmJlNWVhNTJmMDJjMDY3MmMxY2MxM2ZiNGQyNzI3Y2ViZDJiZDE5NmY1N2Q3
|
11
|
+
OTQ1NzM3OTQ1NzRjMTVkOTJjNDcwNjAzNjhiYWZlM2UzZGFjMWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Nzk5OGNkN2ExMTA5MzAwMWMyZDM3NGQyZDJmOTY0MzMzOTM0YTdmNTQ1Y2Q0
|
14
|
+
ZTVjOWFhM2U1NTljYjgzMTJiNTY5YTA5Y2JkMTU1MmJlMjdmNmFhZGZjZDg2
|
15
|
+
NjIxYjBlY2QwMTk1Zjc5ZjdhZDAyYTRlODdkNWQyN2Q5MDEyOGI=
|
data/lib/pseudo_cleaner.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
require "
|
2
|
-
|
3
|
-
|
4
|
-
require "
|
5
|
-
require "
|
6
|
-
require "
|
7
|
-
require "pseudo_cleaner/
|
8
|
-
require "pseudo_cleaner/
|
1
|
+
require "benchmark"
|
2
|
+
|
3
|
+
time = Benchmark.measure do
|
4
|
+
require "sorted_seeder"
|
5
|
+
require "colorize"
|
6
|
+
require "database_cleaner"
|
7
|
+
require "pseudo_cleaner/version"
|
8
|
+
require "pseudo_cleaner/configuration"
|
9
|
+
require "pseudo_cleaner/table_cleaner"
|
10
|
+
require "pseudo_cleaner/master_cleaner"
|
11
|
+
require "pseudo_cleaner/logger"
|
12
|
+
end
|
13
|
+
puts "PseudoCleaner load time: #{time}"
|
9
14
|
|
10
15
|
module PseudoCleaner
|
11
16
|
# Your code goes here...
|
12
|
-
end
|
17
|
+
end
|
@@ -19,6 +19,7 @@ module PseudoCleaner
|
|
19
19
|
attr_accessor :peek_data_not_on_error
|
20
20
|
attr_accessor :enable_full_data_dump_tag
|
21
21
|
attr_accessor :disable_cornucopia_output
|
22
|
+
attr_accessor :benchmark
|
22
23
|
|
23
24
|
def self.current_instance
|
24
25
|
self.instance
|
@@ -35,6 +36,7 @@ module PseudoCleaner
|
|
35
36
|
@peek_data_not_on_error = false
|
36
37
|
@enable_full_data_dump_tag = true
|
37
38
|
@disable_cornucopia_output = false
|
39
|
+
@benchmark = false
|
38
40
|
end
|
39
41
|
|
40
42
|
# Backwards comaptibility...
|
@@ -66,14 +66,19 @@ module PseudoCleaner
|
|
66
66
|
def start_suite(description = nil)
|
67
67
|
description ||= "PseudoCleaner::MasterCleaner.start_suite"
|
68
68
|
|
69
|
-
|
70
|
-
if
|
71
|
-
|
69
|
+
time = Benchmark.measure do
|
70
|
+
puts description if PseudoCleaner::Configuration.instance.benchmark
|
71
|
+
|
72
|
+
within_report_block(description: description) do
|
73
|
+
if @@suite_cleaner
|
74
|
+
@@suite_cleaner.reset_suite
|
75
|
+
end
|
76
|
+
@@suite_cleaner = PseudoCleaner::MasterCleaner.new(:suite)
|
77
|
+
@@suite_cleaner.start :pseudo_delete
|
78
|
+
@@suite_cleaner
|
72
79
|
end
|
73
|
-
@@suite_cleaner = PseudoCleaner::MasterCleaner.new(:suite)
|
74
|
-
@@suite_cleaner.start :pseudo_delete
|
75
|
-
@@suite_cleaner
|
76
80
|
end
|
81
|
+
puts "#{description} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
77
82
|
end
|
78
83
|
|
79
84
|
# def clean_redis(redis)
|
@@ -92,52 +97,69 @@ module PseudoCleaner
|
|
92
97
|
def start_example(example_class, strategy, options = {})
|
93
98
|
options[:description] ||= "PseudoCleaner::MasterCleaner.start_example"
|
94
99
|
|
95
|
-
|
96
|
-
|
97
|
-
|
100
|
+
time = Benchmark.measure do
|
101
|
+
puts options[:description] if PseudoCleaner::Configuration.instance.benchmark
|
102
|
+
|
103
|
+
within_report_block(options) do
|
104
|
+
pseudo_cleaner_data = {}
|
105
|
+
pseudo_cleaner_data[:test_strategy] = strategy
|
98
106
|
|
99
|
-
|
100
|
-
|
107
|
+
unless strategy == :none
|
108
|
+
raise "invalid strategy" unless PseudoCleaner::MasterCleaner::DB_CLEANER_CLEANING_STRATEGIES.has_key? strategy
|
101
109
|
|
102
|
-
|
103
|
-
|
104
|
-
|
110
|
+
DatabaseCleaner.strategy = PseudoCleaner::MasterCleaner::DB_CLEANER_CLEANING_STRATEGIES[strategy]
|
111
|
+
unless [:pseudo_delete].include? strategy
|
112
|
+
PseudoCleaner::MasterCleaner.database_cleaner.start
|
113
|
+
end
|
114
|
+
|
115
|
+
pseudo_cleaner_data[:pseudo_state] = PseudoCleaner::MasterCleaner.start_test strategy
|
105
116
|
end
|
106
117
|
|
107
|
-
pseudo_cleaner_data
|
118
|
+
example_class.instance_variable_set(:@pseudo_cleaner_data, pseudo_cleaner_data)
|
108
119
|
end
|
109
|
-
|
110
|
-
example_class.instance_variable_set(:@pseudo_cleaner_data, pseudo_cleaner_data)
|
111
120
|
end
|
121
|
+
|
122
|
+
puts "#{options[:description]} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
112
123
|
end
|
113
124
|
|
114
125
|
def end_example(example_class, options = {})
|
115
126
|
options[:description] ||= "PseudoCleaner::MasterCleaner.end_example"
|
116
127
|
|
117
|
-
|
118
|
-
|
128
|
+
time = Benchmark.measure do
|
129
|
+
puts options[:description] if PseudoCleaner::Configuration.instance.benchmark
|
119
130
|
|
120
|
-
|
121
|
-
|
122
|
-
PseudoCleaner::MasterCleaner.database_cleaner.clean
|
123
|
-
end
|
131
|
+
within_report_block(options) do
|
132
|
+
pseudo_cleaner_data = example_class.instance_variable_get(:@pseudo_cleaner_data)
|
124
133
|
|
125
|
-
|
126
|
-
|
127
|
-
PseudoCleaner::MasterCleaner.
|
128
|
-
|
134
|
+
unless pseudo_cleaner_data[:test_strategy] == :none
|
135
|
+
unless [:pseudo_delete].include? pseudo_cleaner_data[:test_strategy]
|
136
|
+
PseudoCleaner::MasterCleaner.database_cleaner.clean
|
137
|
+
end
|
138
|
+
|
139
|
+
case pseudo_cleaner_data[:test_strategy]
|
140
|
+
when :deletion, :truncation
|
141
|
+
PseudoCleaner::MasterCleaner.database_reset
|
142
|
+
end
|
129
143
|
|
130
|
-
|
144
|
+
pseudo_cleaner_data[:pseudo_state].end test_type: :test, test_strategy: pseudo_cleaner_data[:test_strategy]
|
145
|
+
end
|
131
146
|
end
|
132
147
|
end
|
148
|
+
puts "#{options[:description]} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
133
149
|
end
|
134
150
|
|
135
151
|
def end_suite(description = nil)
|
136
152
|
description ||= "PseudoCleaner::MasterCleaner.end_suite"
|
137
153
|
|
138
|
-
|
139
|
-
|
154
|
+
time = Benchmark.measure do
|
155
|
+
puts description if PseudoCleaner::Configuration.instance.benchmark
|
156
|
+
|
157
|
+
within_report_block(description: description) do
|
158
|
+
@@suite_cleaner.end test_strategy: :pseudo_delete if @@suite_cleaner
|
159
|
+
end
|
140
160
|
end
|
161
|
+
|
162
|
+
puts "#{description} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
141
163
|
end
|
142
164
|
|
143
165
|
def start_test test_strategy
|
@@ -175,11 +197,16 @@ module PseudoCleaner
|
|
175
197
|
def reset_database(description = nil)
|
176
198
|
description ||= "PseudoCleaner::MasterCleaner.reset_database"
|
177
199
|
|
178
|
-
|
179
|
-
PseudoCleaner::
|
200
|
+
time = Benchmark.measure do
|
201
|
+
puts description if PseudoCleaner::Configuration.instance.benchmark
|
202
|
+
|
203
|
+
within_report_block(description: description) do
|
204
|
+
PseudoCleaner::MasterCleaner.database_cleaner.clean_with(:truncation)
|
180
205
|
|
181
|
-
|
206
|
+
PseudoCleaner::MasterCleaner.database_reset
|
207
|
+
end
|
182
208
|
end
|
209
|
+
puts "#{description} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
183
210
|
end
|
184
211
|
|
185
212
|
def database_reset
|
@@ -254,9 +281,14 @@ module PseudoCleaner
|
|
254
281
|
unless @@cleaner_classes
|
255
282
|
@@cleaner_classes = []
|
256
283
|
|
257
|
-
|
258
|
-
|
259
|
-
|
284
|
+
time = Benchmark.measure do
|
285
|
+
puts " Gathering cleaners" if PseudoCleaner::Configuration.instance.benchmark
|
286
|
+
|
287
|
+
PseudoCleaner::MasterCleaner.create_table_cleaners
|
288
|
+
PseudoCleaner::MasterCleaner.create_custom_cleaners
|
289
|
+
# PseudoCleaner::MasterCleaner.create_redis_cleaners
|
290
|
+
end
|
291
|
+
puts " Gathering cleaners time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
260
292
|
end
|
261
293
|
|
262
294
|
@@cleaner_classes
|
@@ -348,41 +380,54 @@ module PseudoCleaner
|
|
348
380
|
@@report_error = false
|
349
381
|
@@report_table = nil
|
350
382
|
|
351
|
-
|
352
|
-
Cornucopia.const_defined?("Util", false) &&
|
353
|
-
Cornucopia::Util.const_defined?("ReportBuilder", false) &&
|
354
|
-
!PseudoCleaner::Configuration.current_instance.disable_cornucopia_output
|
355
|
-
Cornucopia::Util::ReportBuilder.current_report.within_section(options[:description]) do |report|
|
356
|
-
report.within_hidden_table do |outer_report_table|
|
357
|
-
Cornucopia::Util::ReportTable.new(
|
358
|
-
nested_table: outer_report_table,
|
359
|
-
suppress_blank_table: true) do |report_table|
|
360
|
-
# redundant, but I like it because it is consistent.
|
361
|
-
if options[:location]
|
362
|
-
report_table.write_stats "location", options[:location]
|
363
|
-
end
|
383
|
+
options[:description] ||= "PseudoCleaner::MasterCleaner.peek_data"
|
364
384
|
|
365
|
-
|
385
|
+
time = Benchmark.measure do
|
386
|
+
puts options[:description] if PseudoCleaner::Configuration.instance.benchmark
|
387
|
+
|
388
|
+
if Object.const_defined?("Cornucopia", false) &&
|
389
|
+
Cornucopia.const_defined?("Util", false) &&
|
390
|
+
Cornucopia::Util.const_defined?("ReportBuilder", false) &&
|
391
|
+
!PseudoCleaner::Configuration.current_instance.disable_cornucopia_output
|
392
|
+
Cornucopia::Util::ReportBuilder.current_report.within_section(options[:description]) do |report|
|
393
|
+
report.within_hidden_table do |outer_report_table|
|
394
|
+
Cornucopia::Util::ReportTable.new(
|
395
|
+
nested_table: outer_report_table,
|
396
|
+
suppress_blank_table: true) do |report_table|
|
397
|
+
# redundant, but I like it because it is consistent.
|
398
|
+
if options[:location]
|
399
|
+
report_table.write_stats "location", options[:location]
|
400
|
+
end
|
366
401
|
|
367
|
-
|
402
|
+
@@report_table = report_table
|
403
|
+
|
404
|
+
peek_values
|
405
|
+
end
|
368
406
|
end
|
369
407
|
end
|
370
|
-
end
|
371
408
|
|
372
|
-
|
373
|
-
|
374
|
-
|
409
|
+
@@report_table = nil
|
410
|
+
else
|
411
|
+
PseudoCleaner::Logger.write(options[:description])
|
375
412
|
|
376
|
-
|
413
|
+
peek_values
|
414
|
+
end
|
377
415
|
end
|
416
|
+
|
417
|
+
puts "#{options[:description]} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
378
418
|
end
|
379
419
|
|
380
420
|
def peek_data_new_test(options = {})
|
381
421
|
options[:description] ||= "PseudoCleaner::MasterCleaner.peek_data"
|
382
422
|
|
383
|
-
|
384
|
-
|
423
|
+
time = Benchmark.measure do
|
424
|
+
puts options[:description] if PseudoCleaner::Configuration.instance.benchmark
|
425
|
+
|
426
|
+
within_report_block(options) do
|
427
|
+
peek_values
|
428
|
+
end
|
385
429
|
end
|
430
|
+
puts "#{options[:description]} time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
386
431
|
end
|
387
432
|
|
388
433
|
def peek_values
|
@@ -403,45 +448,50 @@ module PseudoCleaner
|
|
403
448
|
@cleaners = []
|
404
449
|
@test_strategy = test_strategy
|
405
450
|
|
406
|
-
|
407
|
-
|
451
|
+
time = Benchmark.measure do
|
452
|
+
puts " Building cleaners" if PseudoCleaner::Configuration.instance.benchmark
|
408
453
|
|
409
|
-
|
410
|
-
|
411
|
-
table ||= clean_class[1]
|
454
|
+
start_method = "#{test_type}_start".to_sym
|
455
|
+
end_method = "#{test_type}_end".to_sym
|
412
456
|
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
457
|
+
PseudoCleaner::MasterCleaner.cleaner_classes.each do |clean_class|
|
458
|
+
table = clean_class[0]
|
459
|
+
table ||= clean_class[1]
|
460
|
+
|
461
|
+
begin
|
462
|
+
@cleaners << clean_class[2].new(start_method, end_method, table, options)
|
463
|
+
rescue Exception => error
|
464
|
+
puts error.to_s
|
465
|
+
raise error
|
466
|
+
end
|
418
467
|
end
|
419
|
-
end
|
420
468
|
|
421
|
-
|
422
|
-
|
423
|
-
|
469
|
+
unless @@cleaner_classes_sorted
|
470
|
+
seed_sorts = @cleaners.map { |cleaner| SortedSeeder::Seeder::SeederSorter.new(cleaner) }
|
471
|
+
seed_sorts.sort!
|
424
472
|
|
425
|
-
|
473
|
+
@cleaners = seed_sorts.map(&:seed_base_object)
|
426
474
|
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
475
|
+
sorted_classes = []
|
476
|
+
@cleaners.each do |cleaner|
|
477
|
+
cleaner_class = PseudoCleaner::MasterCleaner.cleaner_classes.detect do |unsorted_cleaner|
|
478
|
+
if cleaner.class == unsorted_cleaner[2]
|
479
|
+
if unsorted_cleaner[2] == PseudoCleaner::TableCleaner
|
480
|
+
cleaner.table == unsorted_cleaner[0] || cleaner.table == unsorted_cleaner[1]
|
481
|
+
else
|
482
|
+
true
|
483
|
+
end
|
435
484
|
end
|
436
485
|
end
|
486
|
+
|
487
|
+
sorted_classes << cleaner_class
|
437
488
|
end
|
438
489
|
|
439
|
-
sorted_classes
|
490
|
+
@@cleaner_classes = sorted_classes
|
491
|
+
@@cleaner_classes_sorted = true
|
440
492
|
end
|
441
|
-
|
442
|
-
@@cleaner_classes = sorted_classes
|
443
|
-
@@cleaner_classes_sorted = true
|
444
493
|
end
|
494
|
+
puts " Building cleaners time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
445
495
|
end
|
446
496
|
|
447
497
|
start_all_cleaners options
|
@@ -372,9 +372,15 @@ module PseudoCleaner
|
|
372
372
|
end
|
373
373
|
|
374
374
|
def suite_start test_strategy
|
375
|
-
|
375
|
+
time = Benchmark.measure do
|
376
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
377
|
+
|
378
|
+
@test_strategy ||= test_strategy
|
376
379
|
|
377
|
-
|
380
|
+
start_monitor
|
381
|
+
end
|
382
|
+
|
383
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
378
384
|
end
|
379
385
|
|
380
386
|
def suspend_tracking(&block)
|
@@ -390,52 +396,76 @@ module PseudoCleaner
|
|
390
396
|
def test_start test_strategy
|
391
397
|
@test_strategy ||= test_strategy
|
392
398
|
|
393
|
-
|
394
|
-
|
395
|
-
|
399
|
+
time = Benchmark.measure do
|
400
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
401
|
+
|
402
|
+
synchronize_test_values do |test_values|
|
403
|
+
if test_values && !test_values.empty?
|
404
|
+
report_dirty_values "values altered before the test started", test_values
|
396
405
|
|
397
|
-
|
398
|
-
|
406
|
+
test_values.each do |value|
|
407
|
+
redis.del value unless initial_keys.include?(value)
|
408
|
+
end
|
399
409
|
end
|
400
410
|
end
|
411
|
+
|
412
|
+
@updated_keys = SortedSet.new
|
401
413
|
end
|
402
414
|
|
403
|
-
|
415
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
404
416
|
end
|
405
417
|
|
406
418
|
def test_end test_strategy
|
407
|
-
|
408
|
-
|
409
|
-
report_keys = []
|
419
|
+
time = Benchmark.measure do
|
420
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
410
421
|
|
411
|
-
|
412
|
-
|
413
|
-
|
422
|
+
synchronize_test_values do |updated_values|
|
423
|
+
if updated_values && !updated_values.empty?
|
424
|
+
report_keys = []
|
414
425
|
|
415
|
-
|
416
|
-
|
417
|
-
report_keys << value
|
418
|
-
@suite_altered_keys << value unless ignore_key(value)
|
419
|
-
else
|
420
|
-
redis.del(value)
|
426
|
+
if @options[:output_diagnostics]
|
427
|
+
report_dirty_values "updated values", updated_values
|
421
428
|
end
|
422
|
-
end
|
423
429
|
|
424
|
-
|
430
|
+
updated_values.each do |value|
|
431
|
+
if initial_keys.include?(value)
|
432
|
+
report_keys << value
|
433
|
+
@suite_altered_keys << value unless ignore_key(value)
|
434
|
+
else
|
435
|
+
redis.del(value)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
report_dirty_values "initial values altered by test", report_keys
|
440
|
+
end
|
425
441
|
end
|
442
|
+
|
443
|
+
@updated_keys = SortedSet.new
|
426
444
|
end
|
427
445
|
|
428
|
-
|
446
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
429
447
|
end
|
430
448
|
|
431
449
|
def suite_end test_strategy
|
432
|
-
|
450
|
+
time = Benchmark.measure do
|
451
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
452
|
+
|
453
|
+
report_end_of_suite_state "suite end"
|
454
|
+
end
|
455
|
+
|
456
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
433
457
|
end
|
434
458
|
|
435
459
|
def reset_suite
|
436
|
-
|
460
|
+
time = Benchmark.measure do
|
461
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
437
462
|
|
438
|
-
|
463
|
+
report_end_of_suite_state "reset suite"
|
464
|
+
|
465
|
+
start_monitor
|
466
|
+
end
|
467
|
+
|
468
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
439
469
|
end
|
440
470
|
|
441
471
|
def ignore_regexes
|
@@ -456,47 +486,59 @@ module PseudoCleaner
|
|
456
486
|
end
|
457
487
|
|
458
488
|
def review_rows(&block)
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
489
|
+
time = Benchmark.measure do
|
490
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
491
|
+
|
492
|
+
synchronize_test_values do |updated_values|
|
493
|
+
if updated_values && !updated_values.empty?
|
494
|
+
updated_values.each do |updated_value|
|
495
|
+
unless ignore_key(updated_value)
|
496
|
+
block.yield redis_name, report_record(updated_value)
|
497
|
+
end
|
464
498
|
end
|
465
499
|
end
|
466
500
|
end
|
467
501
|
end
|
502
|
+
|
503
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
468
504
|
end
|
469
505
|
|
470
506
|
def peek_values
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
if
|
476
|
-
|
477
|
-
|
478
|
-
|
507
|
+
time = Benchmark.measure do
|
508
|
+
puts " RedisCleaner(#{redis_name})" if PseudoCleaner::Configuration.instance.benchmark
|
509
|
+
|
510
|
+
synchronize_test_values do |updated_values|
|
511
|
+
if updated_values && !updated_values.empty?
|
512
|
+
output_values = false
|
513
|
+
|
514
|
+
if PseudoCleaner::MasterCleaner.report_table
|
515
|
+
Cornucopia::Util::ReportTable.new(nested_table: PseudoCleaner::MasterCleaner.report_table,
|
516
|
+
nested_table_label: redis_name,
|
517
|
+
suppress_blank_table: true) do |report_table|
|
518
|
+
updated_values.each_with_index do |updated_value, index|
|
519
|
+
unless ignore_key(updated_value)
|
520
|
+
output_values = true
|
521
|
+
report_table.write_stats index.to_s, report_record(updated_value)
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
else
|
526
|
+
PseudoCleaner::Logger.write(" #{redis_name}")
|
527
|
+
|
479
528
|
updated_values.each_with_index do |updated_value, index|
|
480
529
|
unless ignore_key(updated_value)
|
481
530
|
output_values = true
|
482
|
-
|
531
|
+
PseudoCleaner::Logger.write(" #{index}: #{report_record(updated_value)}")
|
483
532
|
end
|
484
533
|
end
|
485
534
|
end
|
486
|
-
else
|
487
|
-
PseudoCleaner::Logger.write(" #{redis_name}")
|
488
535
|
|
489
|
-
|
490
|
-
unless ignore_key(updated_value)
|
491
|
-
output_values = true
|
492
|
-
PseudoCleaner::Logger.write(" #{index}: #{report_record(updated_value)}")
|
493
|
-
end
|
494
|
-
end
|
536
|
+
PseudoCleaner::MasterCleaner.report_error if output_values
|
495
537
|
end
|
496
|
-
|
497
|
-
PseudoCleaner::MasterCleaner.report_error if output_values
|
498
538
|
end
|
499
539
|
end
|
540
|
+
|
541
|
+
puts " RedisCleaner(#{redis_name}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
500
542
|
end
|
501
543
|
|
502
544
|
def report_end_of_suite_state report_reason
|
@@ -5,7 +5,15 @@ module PseudoCleaner
|
|
5
5
|
@@initial_states = {}
|
6
6
|
|
7
7
|
def reset_suite
|
8
|
-
|
8
|
+
initial_state = @@initial_states[@table]
|
9
|
+
|
10
|
+
time = Benchmark.measure do
|
11
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
12
|
+
|
13
|
+
@@initial_states = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
9
17
|
end
|
10
18
|
|
11
19
|
def initialize(start_method, end_method, table, options = {})
|
@@ -70,12 +78,28 @@ module PseudoCleaner
|
|
70
78
|
|
71
79
|
def test_start test_strategy
|
72
80
|
@test_strategy ||= test_strategy
|
73
|
-
|
81
|
+
initial_state = @@initial_states[@table]
|
82
|
+
|
83
|
+
time = Benchmark.measure do
|
84
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
85
|
+
|
86
|
+
save_state
|
87
|
+
end
|
88
|
+
|
89
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
74
90
|
end
|
75
91
|
|
76
92
|
def suite_start test_strategy
|
77
93
|
@test_strategy ||= test_strategy
|
78
|
-
|
94
|
+
initial_state = @@initial_states[@table]
|
95
|
+
|
96
|
+
time = Benchmark.measure do
|
97
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
98
|
+
|
99
|
+
save_state
|
100
|
+
end
|
101
|
+
|
102
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
79
103
|
end
|
80
104
|
|
81
105
|
def within_report_block(description, conditional, &block)
|
@@ -243,58 +267,79 @@ module PseudoCleaner
|
|
243
267
|
def test_end test_strategy
|
244
268
|
initial_state = @@initial_states[@table]
|
245
269
|
|
246
|
-
|
247
|
-
|
270
|
+
time = Benchmark.measure do
|
271
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
272
|
+
|
273
|
+
|
274
|
+
within_report_block(initial_state[:table_name], @options[:output_diagnostics]) do
|
275
|
+
reset_table test_strategy, false, false
|
276
|
+
end
|
248
277
|
end
|
278
|
+
|
279
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
249
280
|
end
|
250
281
|
|
251
282
|
def suite_end test_strategy
|
252
283
|
initial_state = @@initial_states[@table]
|
253
284
|
|
254
|
-
|
255
|
-
|
285
|
+
time = Benchmark.measure do
|
286
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
287
|
+
|
288
|
+
|
289
|
+
within_report_block(initial_state[:table_name], @options[:output_diagnostics]) do
|
290
|
+
reset_table test_strategy, true, true
|
291
|
+
end
|
256
292
|
end
|
293
|
+
|
294
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
257
295
|
end
|
258
296
|
|
259
297
|
def reset_table test_strategy, require_output, is_suite_end
|
260
298
|
initial_state = @@initial_states[@table]
|
261
299
|
|
262
|
-
|
263
|
-
|
264
|
-
PseudoCleaner::MasterCleaner.report_error
|
300
|
+
time = Benchmark.measure do
|
301
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
265
302
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
PseudoCleaner::
|
303
|
+
|
304
|
+
if @test_strategy != test_strategy && !PseudoCleaner::Configuration.current_instance.single_cleaner_set
|
305
|
+
if @options[:output_diagnostics]
|
306
|
+
PseudoCleaner::MasterCleaner.report_error
|
307
|
+
|
308
|
+
if @report_table
|
309
|
+
@report_table.write_stats("WARNING", "*** The ending strategy for \"#{initial_state[:table_name]}\" changed! ***")
|
310
|
+
else
|
311
|
+
PseudoCleaner::Logger.write(" *** The ending strategy for \"#{initial_state[:table_name]}\" changed! ***".red.on_light_white)
|
312
|
+
end
|
270
313
|
end
|
271
314
|
end
|
272
|
-
end
|
273
315
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
316
|
+
if test_strategy == :pseudo_delete || PseudoCleaner::Configuration.current_instance.post_transaction_analysis
|
317
|
+
# we should check the relationships for any records which still refer to
|
318
|
+
# a now deleted record. (i.e. if we updated a record to refer to a record)
|
319
|
+
# we deleted...
|
320
|
+
#
|
321
|
+
# Which is why this is not a common or particularly good solution.
|
322
|
+
#
|
323
|
+
# I'm using it because it is faster than reseeding each test...
|
324
|
+
# And, I can be responsible for worrying about referential integrity in the test
|
325
|
+
# if I want to...
|
326
|
+
pre_string = " Resetting table \"#{initial_state[:table_name]}\" for #{test_strategy}..."
|
327
|
+
pre_string = "Tests ended without cleaning up properly!!!\n" + pre_string if require_output
|
328
|
+
pre_string = pre_string.red.on_light_white if require_output
|
287
329
|
|
288
|
-
|
330
|
+
require_output ||= @options[:output_diagnostics]
|
289
331
|
|
290
|
-
|
291
|
-
|
292
|
-
|
332
|
+
if initial_state[:table_is_active_record]
|
333
|
+
test_end_active_record test_strategy, pre_string, require_output, is_suite_end
|
334
|
+
end
|
293
335
|
|
294
|
-
|
295
|
-
|
336
|
+
if initial_state[:table_is_sequel_model]
|
337
|
+
test_end_sequel_model test_strategy, pre_string, require_output, is_suite_end
|
338
|
+
end
|
296
339
|
end
|
297
340
|
end
|
341
|
+
|
342
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
298
343
|
end
|
299
344
|
|
300
345
|
def test_end_active_record test_strategy, pre_string, require_output, is_suite_end
|
@@ -646,15 +691,22 @@ module PseudoCleaner
|
|
646
691
|
def review_rows(&block)
|
647
692
|
initial_state = @@initial_states[@table]
|
648
693
|
|
649
|
-
|
650
|
-
|
651
|
-
review_rows_active_record &block
|
652
|
-
end
|
694
|
+
time = Benchmark.measure do
|
695
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
653
696
|
|
654
|
-
|
655
|
-
|
697
|
+
|
698
|
+
if initial_state
|
699
|
+
if initial_state[:table_is_active_record]
|
700
|
+
review_rows_active_record &block
|
701
|
+
end
|
702
|
+
|
703
|
+
if initial_state[:table_is_sequel_model]
|
704
|
+
review_rows_sequel_model &block
|
705
|
+
end
|
656
706
|
end
|
657
707
|
end
|
708
|
+
|
709
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
658
710
|
end
|
659
711
|
|
660
712
|
def review_rows_active_record(&block)
|
@@ -714,35 +766,43 @@ module PseudoCleaner
|
|
714
766
|
end
|
715
767
|
|
716
768
|
def peek_values
|
717
|
-
row_data
|
718
|
-
peek_name
|
769
|
+
row_data = []
|
770
|
+
peek_name = nil
|
771
|
+
initial_state = @@initial_states[@table]
|
719
772
|
|
720
|
-
|
721
|
-
|
722
|
-
row_data << table_values
|
723
|
-
end
|
773
|
+
time = Benchmark.measure do
|
774
|
+
puts " TableCleaner(#{initial_state[:table_name]})" if PseudoCleaner::Configuration.instance.benchmark
|
724
775
|
|
725
|
-
if row_data && !row_data.empty?
|
726
|
-
output_values = false
|
727
776
|
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
777
|
+
review_rows do |table_name, table_values|
|
778
|
+
peek_name = table_name
|
779
|
+
row_data << table_values
|
780
|
+
end
|
781
|
+
|
782
|
+
if row_data && !row_data.empty?
|
783
|
+
output_values = false
|
784
|
+
|
785
|
+
if PseudoCleaner::MasterCleaner.report_table
|
786
|
+
Cornucopia::Util::ReportTable.new(nested_table: PseudoCleaner::MasterCleaner.report_table,
|
787
|
+
nested_table_label: peek_name,
|
788
|
+
suppress_blank_table: true) do |report_table|
|
789
|
+
row_data.each_with_index do |row, row_index|
|
790
|
+
report_table.write_stats row_index.to_s, row
|
791
|
+
end
|
734
792
|
end
|
735
|
-
|
736
|
-
|
737
|
-
PseudoCleaner::Logger.write(" #{peek_name}")
|
793
|
+
else
|
794
|
+
PseudoCleaner::Logger.write(" #{peek_name}")
|
738
795
|
|
739
|
-
|
740
|
-
|
796
|
+
row_data.each_with_index do |updated_value, index|
|
797
|
+
PseudoCleaner::Logger.write(" #{index}: #{updated_value}")
|
798
|
+
end
|
741
799
|
end
|
742
|
-
end
|
743
800
|
|
744
|
-
|
801
|
+
PseudoCleaner::MasterCleaner.report_error
|
802
|
+
end
|
745
803
|
end
|
804
|
+
|
805
|
+
puts " TableCleaner(#{initial_state[:table_name]}) time: #{time}" if PseudoCleaner::Configuration.instance.benchmark
|
746
806
|
end
|
747
807
|
end
|
748
808
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pseudo_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.43
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RealNobody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|