fsevent 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a29fe94eaba408b87373eb438cb5586bc0d97906
4
- data.tar.gz: 837f02c21999e8b41e86e22066d0f198111cbb0c
3
+ metadata.gz: c80e06a6aa6324c5a9d77f57fea9c837d34c335c
4
+ data.tar.gz: 0522ec2031f9b54b06719c7c97dc7d6fb7d5a31c
5
5
  SHA512:
6
- metadata.gz: 2e163903a427283fa54b05c675a5aa806f872c750e8da21f3e084061efdc3457e552cc5eeda138cef43f2671c04a703cec9b6143e13106c4ccfdc6d9cbfd7981
7
- data.tar.gz: 902f766db3e5148e76c60bfd25f245bbd738b423a6d15a89545ff98c19a650ee05fdb1479ca6f59ed966a9276682e1189e13c25dfbd3b0f4377852d6525e5300
6
+ metadata.gz: 655e1f86025488fa852eadb61f5df04c604d062e7aa2e7019e9b12c2b2919b92489c4f3d132b923fd10d9eacdde7815fa7b443842c89f38e3686cd63cfe04dba
7
+ data.tar.gz: b1f09c8e4526f7c1c0550a2d623d72469312ce0ce916098b20a7f13ba4f4de38a9f7d963ef6f13f58d69d911cacb36eb8ef1199172ce03760ce6a9b0dff233b1
data/fsevent.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'fsevent'
3
- s.version = '0.2'
3
+ s.version = '0.3'
4
4
  s.date = '2013-06-30'
5
5
  s.author = 'Tanaka Akira'
6
6
  s.email = 'tanaka-akira@aist.go.jp'
@@ -51,8 +51,7 @@ class FSEvent
51
51
  raise ArgumentError, "invalid device name: #{device_name.inspect}"
52
52
  end
53
53
  if !Thread.current[:fsevent_buffer]
54
- value = [:register_start, device_name, device]
55
- @schedule_locator[device_name] = @q.insert value, @current_time
54
+ internal_register_device(device_name, device)
56
55
  else
57
56
  value = [:register_device, device_name, device]
58
57
  Thread.current[:fsevent_buffer] << value
@@ -185,7 +184,7 @@ class FSEvent
185
184
  private :at_register_end
186
185
 
187
186
  def at_run_start(loc, device_name)
188
- time = loc.priority
187
+ time = @current_time
189
188
  device = @devices[device_name]
190
189
 
191
190
  watched_status, changed_status = notifications(device_name, @device_last_run_count[device_name])
@@ -224,7 +223,7 @@ class FSEvent
224
223
 
225
224
  def at_run_end(loc, device_name, run_start_count, buffer)
226
225
  @device_last_run_count[device_name] = run_start_count
227
- run_end_time = loc.priority
226
+ run_end_time = @current_time
228
227
 
229
228
  wakeup_immediate = false
230
229
  unregister_self = false
@@ -242,7 +241,7 @@ class FSEvent
242
241
  when :del_watch
243
242
  internal_del_watch(device_name, *rest)
244
243
  when :register_device
245
- internal_register_device(device_name, *rest)
244
+ internal_register_device(*rest)
246
245
  when :unregister_device
247
246
  unregister_self |= internal_unregister_device(device_name, *rest)
248
247
  else
@@ -257,10 +256,11 @@ class FSEvent
257
256
  end
258
257
  private :at_run_end
259
258
 
260
- def internal_register_device(device_name, target_device_name, device)
259
+ def internal_register_device(target_device_name, device)
261
260
  value = [:register_start, target_device_name, device]
262
261
  @schedule_locator[target_device_name] = @q.insert value, @current_time
263
262
  end
263
+ private :internal_register_device
264
264
 
265
265
  def internal_define_status(device_name, run_end_time, status_name, value)
266
266
  internal_define_status2(device_name, run_end_time, status_name, value)
@@ -293,7 +293,11 @@ class FSEvent
293
293
  @status_time[device_name][status_name] = @current_time
294
294
  @status_count[device_name][status_name] = @current_count
295
295
  lookup_watchers(device_name, status_name).each {|watcher_device_name, reaction|
296
- set_wakeup_if_possible(watcher_device_name, run_end_time) if reaction_immediate_at_beginning? reaction
296
+ if reaction_immediate_at_beginning? reaction
297
+ if watcher_device_name != device_name
298
+ set_wakeup_if_possible(watcher_device_name, run_end_time)
299
+ end
300
+ end
297
301
  }
298
302
  end
299
303
  private :internal_define_status2
@@ -314,7 +318,11 @@ class FSEvent
314
318
  @status_time[device_name][status_name] = @current_time
315
319
  @status_count[device_name][status_name] = @current_count
316
320
  lookup_watchers(device_name, status_name).each {|watcher_device_name, reaction|
317
- set_wakeup_if_possible(watcher_device_name, run_end_time) if reaction_immediate_at_subsequent? reaction
321
+ if watcher_device_name != device_name
322
+ if reaction_immediate_at_subsequent? reaction
323
+ set_wakeup_if_possible(watcher_device_name, run_end_time)
324
+ end
325
+ end
318
326
  }
319
327
  end
320
328
  private :internal_modify_status2
@@ -330,7 +338,11 @@ class FSEvent
330
338
  @status_time[device_name][status_name] = @current_time
331
339
  @status_count[device_name][status_name] = @current_count
332
340
  lookup_watchers(device_name, status_name).each {|watcher_device_name, reaction|
333
- set_wakeup_if_possible(watcher_device_name, run_end_time) if reaction_immediate_at_subsequent? reaction
341
+ if watcher_device_name != device_name
342
+ if reaction_immediate_at_subsequent? reaction
343
+ set_wakeup_if_possible(watcher_device_name, run_end_time)
344
+ end
345
+ end
334
346
  }
335
347
  internal_update_status(device_name, run_end_time, "_status_undefined_#{status_name}", run_end_time)
336
348
  end
@@ -407,8 +419,13 @@ class FSEvent
407
419
  end
408
420
  case event_type = loc.value.first
409
421
  when :run_start # The device is sleeping now.
410
- if time < loc.priority
411
- loc.update_priority time
422
+ if time != loc.priority
423
+ if time < loc.priority
424
+ @devices[device_name].schedule.merge_schedule([loc.priority])
425
+ loc.update_priority time
426
+ else
427
+ @devices[device_name].schedule.merge_schedule([time])
428
+ end
412
429
  end
413
430
  when :run_end # The device is working now.
414
431
  # Nothing to do. at_run_end itself checks arrived events at last.
@@ -424,10 +441,10 @@ class FSEvent
424
441
  if wakeup_immediate
425
442
  run_start_time = run_end_time
426
443
  elsif run_start_time = device.schedule.shift
427
- if run_start_time < run_end_time
444
+ if run_start_time <= run_end_time
428
445
  run_start_time = run_end_time
429
446
  end
430
- while device.schedule.first && device.schedule.first < run_end_time
447
+ while device.schedule.first && device.schedule.first <= run_end_time
431
448
  device.schedule.shift
432
449
  end
433
450
  end
@@ -44,5 +44,11 @@ class FSEvent::ScheduleMerger
44
44
  end
45
45
  t
46
46
  end
47
+
48
+ def clear
49
+ until @q.empty?
50
+ @q.delete_min
51
+ end
52
+ end
47
53
  end
48
54
 
@@ -24,7 +24,7 @@ class TestFSEventFailSafeDevice < Test::Unit::TestCase
24
24
  super device_name
25
25
  @init = init
26
26
  @elapsed = 1
27
- @schedule = pairs.map {|t, v| t-@elapsed }
27
+ @schedule.merge_schedule pairs.map {|t, v| t-@elapsed }
28
28
  @values = pairs.map {|t, v| v }
29
29
  @test_result = []
30
30
  end
@@ -80,7 +80,7 @@ class TestFSEventFramework < Test::Unit::TestCase
80
80
  device.schedule.merge_schedule(schedule)
81
81
  def device.run(watched_status, changed_status)
82
82
  @test_result << @framework.current_time
83
- @schedule = [] if 2 < @test_result.length
83
+ @schedule.clear if 2 < @test_result.length
84
84
  end
85
85
  fsevent.register_device(device)
86
86
  assert_nothing_raised { fsevent.start }
@@ -340,4 +340,66 @@ class TestFSEventFramework < Test::Unit::TestCase
340
340
  assert_equal([t+20], result)
341
341
  end
342
342
 
343
+ def test_too_long_run
344
+ t = Time.utc(2000)
345
+ fse = FSEvent.new(t)
346
+ result = []
347
+ d1 = FSEvent::SimpleDevice.new("d2", {}, [], 1, [t+10, t+20, t+30]) {|watched_status, changed_status|
348
+ fse.set_elapsed_time(15)
349
+ result << fse.current_time
350
+ }
351
+ fse.register_device d1
352
+ fse.start
353
+ assert_equal([t+10, t+25, t+40], result)
354
+ end
355
+
356
+ def test_too_long_run_2
357
+ t = Time.utc(2000)
358
+ fse = FSEvent.new(t)
359
+ result = []
360
+ d1 = FSEvent::SimpleDevice.new("d2", {}, [], 1, [t+10, t+20, t+30]) {|watched_status, changed_status|
361
+ fse.set_elapsed_time(25)
362
+ result << fse.current_time
363
+ }
364
+ fse.register_device d1
365
+ fse.start
366
+ assert_equal([t+10, t+35], result)
367
+ end
368
+
369
+ def test_immediate_and_scheduled_event
370
+ t = Time.utc(2000)
371
+ fse = FSEvent.new(t)
372
+ d1 = FSEvent::SimpleDevice.new("d1", {"s"=>0}, [], 0, [t+10]) {|watched_status, changed_status|
373
+ fse.modify_status("s", 1)
374
+ fse.set_elapsed_time(10)
375
+ }
376
+ result = []
377
+ d2 = FSEvent::SimpleDevice.new("d2", {}, [["d1", "s", :immediate]], 0, [t+300]) {|watched_status, changed_status|
378
+ fse.set_elapsed_time(0)
379
+ result << fse.current_time
380
+ }
381
+ fse.register_device d1
382
+ fse.register_device d2
383
+ fse.start
384
+ assert_equal([t, t+20, t+300], result)
385
+ end
386
+
387
+ def test_self_watch
388
+ t = Time.utc(2000)
389
+ fse = FSEvent.new(t)
390
+ result = []
391
+ n = 0
392
+ d1 = FSEvent::SimpleDevice.new("d1", {"s"=>n}, [["d1", "s", :immediate]], 0, []) {|watched_status, changed_status|
393
+ result << fse.current_time
394
+ if n < 4
395
+ n += 1
396
+ fse.modify_status("s", n)
397
+ end
398
+ fse.set_elapsed_time(4)
399
+ }
400
+ fse.register_device d1
401
+ fse.start
402
+ assert_equal([t, t+4, t+8, t+12, t+16], result)
403
+ end
404
+
343
405
  end
data/test/test_watch.rb CHANGED
@@ -89,7 +89,8 @@ class TestFSEventWatch < Test::Unit::TestCase
89
89
  fsevent.start
90
90
  assert_equal(
91
91
  [[t + 1, {"src"=>{"s"=>0}}],
92
- [t + 15, {"src"=>{"s"=>100}}]],
92
+ [t + 15, {"src"=>{"s"=>100}}],
93
+ [t + 20, {"src"=>{"s"=>100}}]],
93
94
  test_result)
94
95
  end
95
96
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fsevent
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira