zhong 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f1dac5a4ab2bbf39455eb3ae3aa85b8db281f71
4
- data.tar.gz: bad4a27f7f28e8d9e09bd89e722c8d14de24135f
3
+ metadata.gz: e8e24ce8cbfc3ebd6b0574c791aef211bb0777c1
4
+ data.tar.gz: cd327270c61bbfb6817096ff5e2f2aee1ade850e
5
5
  SHA512:
6
- metadata.gz: 09b25ced5faf77601dcc4056f32441cdf9183a542e4fcdc87ce689806e38e1fc1189613ff9ca11f776c8967e1c4fba9bab83049022860c21ab4893255c64fa4b
7
- data.tar.gz: 50d880d5819a8d103d99740a1cacd3a828277015d0def4d486fa777d20f082daa7c1e9d6a56f89469de22f3d9c26245b056165fad4f2339b7fcc45647471a4fd
6
+ metadata.gz: b5955bed476e79f2b79520523724320404733986912bda9d3d6fc1396c578a935336fd2927295579f9bfe838baf2ee4d55ff953ab6a0f5f4332d3afb85ad0678
7
+ data.tar.gz: e8082120c278422e3d1f04660739877d4d7fba6573745c31f63df0df4116d719a424087e1d3b8ac06d863d1dd0c98ebfd3489a7e411dcebe08228a1c6fc07ec4
@@ -1,3 +1,8 @@
1
+ ## 0.1.7
2
+
3
+ - Improve test coverage.
4
+ - Fix a small serialization issue.
5
+
1
6
  ## 0.1.6
2
7
 
3
8
  - Add Zhong.any_running? for monitoring that any Zhong node has checked in rencently
@@ -71,6 +71,10 @@ module Zhong
71
71
  MessagePack.pack(as_json)
72
72
  end
73
73
 
74
+ def ==(other)
75
+ other.class == self.class && other.state == state
76
+ end
77
+
74
78
  def self.parse_serialized(at)
75
79
  if at.is_a?(Array)
76
80
  MultiAt.new(at.map { |a| parse_serialized(a) })
@@ -114,10 +118,6 @@ module Zhong
114
118
  end
115
119
  end
116
120
 
117
- def ==(other)
118
- other.class == self.class && other.state == state
119
- end
120
-
121
121
  def state
122
122
  [@minute, @hour, @wday]
123
123
  end
@@ -45,10 +45,7 @@ module Zhong
45
45
 
46
46
  job = Job.new(name, opts.merge(@config).merge(every: period, category: @category), &block)
47
47
 
48
- if jobs.key?(job.id)
49
- @logger.error "duplicate job #{job}, skipping"
50
- return
51
- end
48
+ raise "duplicate job #{job}" if jobs.key?(job.id)
52
49
 
53
50
  @jobs[job.id] = job
54
51
  end
@@ -1,3 +1,3 @@
1
1
  module Zhong
2
- VERSION = "0.1.6".freeze
2
+ VERSION = "0.1.7".freeze
3
3
  end
@@ -10,6 +10,7 @@ module Zhong
10
10
  enable :sessions
11
11
  use ::Rack::Protection, use: :authenticity_token unless ENV["RACK_ENV"] == "test"
12
12
 
13
+ # :nocov:
13
14
  if ENV["ZHONG_WEB_USERNAME"] && ENV["ZHONG_WEB_PASSWORD"]
14
15
  use Rack::Auth::Basic, "Sorry." do |username, password|
15
16
  username == ENV["ZHONG_WEB_USERNAME"] and password == ENV["ZHONG_WEB_PASSWORD"]
@@ -21,6 +22,7 @@ module Zhong
21
22
  STDERR.puts "[params] #{params}" unless params.empty?
22
23
  end
23
24
  end
25
+ # :nocov:
24
26
 
25
27
  set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
26
28
  set :public_folder, proc { "#{root}/assets" }
@@ -69,10 +71,12 @@ if defined?(::ActionDispatch::Request::Session) && !::ActionDispatch::Request::S
69
71
  # mperham/sidekiq#2460
70
72
  # Rack apps can't reuse the Rails session store without
71
73
  # this monkeypatch
74
+ # :nocov:
72
75
  class ActionDispatch::Request::Session
73
76
  def each(&block)
74
77
  hash = self.to_hash
75
78
  hash.each(&block)
76
79
  end
77
80
  end
81
+ # :nocov:
78
82
  end
@@ -159,12 +159,18 @@ class TestAt < Minitest::Test
159
159
  assert_equal([{m: nil, h: 8, w: nil, g: 0.seconds}, {m: 30, h: 12, w: 0, g: 0.seconds}], at.as_json)
160
160
  end
161
161
 
162
- def test_serialize
162
+ def test_serialize_multi
163
163
  at = Zhong::At.parse(["8:20", "tues 12:30"])
164
164
 
165
165
  assert_equal Zhong::At.deserialize(at.serialize), at
166
166
  end
167
167
 
168
+ def test_serialize_single
169
+ at = Zhong::At.parse("sun 14:20")
170
+
171
+ assert_equal Zhong::At.deserialize(at.serialize), at
172
+ end
173
+
168
174
  def test_invalid_time_32
169
175
  assert_raises Zhong::At::FailedToParse do
170
176
  Zhong::At.parse("32:00")
@@ -10,12 +10,19 @@ class TestLibrary < Minitest::Test
10
10
  sleep 1
11
11
  end
12
12
 
13
+ def test_logger
14
+ test_logger = Zhong.logger
15
+ Zhong.logger = nil
16
+ assert_output(nil, nil) { Zhong.logger.info "ensure has default logger" }
17
+ Zhong.logger = test_logger
18
+ end
19
+
13
20
  def test_heartbeats
14
21
  Zhong.schedule { nil }
15
22
  t = Thread.new { Zhong.start }
16
23
  sleep(1)
17
24
  assert_equal true, Zhong.any_running?
18
- assert_in_delta Zhong.redis_time.to_f, Time.now.to_f, 0.1
25
+ assert_in_delta Zhong.redis_time.to_f, Time.now.to_f, 1
19
26
  assert_in_delta Zhong.redis_time.to_f, Zhong.latest_heartbeat.to_f, 1
20
27
  Zhong.stop
21
28
  t.join
@@ -44,6 +44,17 @@ class TestScheduler < Minitest::Test
44
44
  end
45
45
  end
46
46
 
47
+ def test_duplicate_job_name
48
+ boom = assert_raises RuntimeError do
49
+ Zhong.schedule do
50
+ every(1.second, "dupe_job") { nil }
51
+ every(1.second, "dupe_job") { nil }
52
+ end
53
+ end
54
+
55
+ assert_match(/duplicate job dupe_job/, boom.message)
56
+ end
57
+
47
58
  def test_scheduler_callbacks
48
59
  test_before_tick = 0
49
60
  test_after_tick = 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhong
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Elser