timeout-extensions 0.0.0 → 0.1.0

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: 4ad2130b411b304b307f17a4db55b4c034ff84ff
4
- data.tar.gz: 0566ffbb332db2b4bdf1862474a97f9ec5d6a451
3
+ metadata.gz: ac5f8d21d026acd98f1d9dd234e7a580a8efa2bc
4
+ data.tar.gz: fa3e5860cf5f98d836d8e3cb1350913453163dbf
5
5
  SHA512:
6
- metadata.gz: 61f6d8bb54f5b00b49e14847bce4d219f26faf76fd6854bcfec4e1fe9fab30b747504ebd2411720c680ee940612bca3e1a766d46b8cd1e080d390cb61872c3cd
7
- data.tar.gz: 2bf51f1671ebcea3dd664d40141e07ed9a541a3c16a3bf9001a35158bf274efd8a1bc86c15043a8f000396606acf94707ee5ba9725e11da027cf3ce642cb2d03
6
+ metadata.gz: 326430abdffa6d8a8c21dc101a802cb193545fc1648b2c345c392aca3d899a1b648cf49f0d9e2885387358d8d6667cbd62c95fb012faab8365d5b84f0f20c878
7
+ data.tar.gz: 50a5b3f7b721d8f181dd533ecf53d2c2b0c4fcb417b8530af6b5fe060e9c5b4de7c5ec90e5d0737e27fb233385440716b6fb6f17e1aca4e9634a3a68ddaf957c
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+
4
+ #
5
+ # Style
6
+ #
7
+
8
+ LineLength:
9
+ Max: 128
10
+
11
+ Style/StringLiterals:
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/SpaceBeforeFirstArg:
15
+ Enabled: false
16
+
17
+ Style/ConditionalAssignment:
18
+ Enabled: false
19
+
20
+ Style/ClassAndModuleChildren:
21
+ Enabled: false
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ #
27
+ # Metrics
28
+ #
29
+
30
+ Metrics/MethodLength:
31
+ Max: 20
32
+
33
+ Metrics/AbcSize:
34
+ Max: 20
data/.travis.yml ADDED
@@ -0,0 +1,25 @@
1
+ language: ruby
2
+ sudo: false
3
+
4
+ bundler_args: --without development doc
5
+
6
+ rvm:
7
+ - 2.1
8
+ - 2.2
9
+ - 2.3.0
10
+ - 2.3.1
11
+ - jruby-9.1.0.0
12
+ - jruby-head
13
+ - ruby-head
14
+ - rbx-2
15
+
16
+ matrix:
17
+ allow_failures:
18
+ - rvm: jruby-head
19
+ - rvm: ruby-head
20
+ - rvm: rbx-2
21
+ fast_finish: true
22
+
23
+ branches:
24
+ only:
25
+ - master
data/CHANGES.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0 (2016-07-02)
2
+
3
+ * Initial release.
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in timeout.gemspec
4
3
  gemspec
4
+
5
+ group :development, :test do
6
+ gem "rake"
7
+ end
8
+
9
+ group :test do
10
+ gem "rspec", "~> 3", require: false
11
+ gem "rubocop", "0.41.1", require: false
12
+ end
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Timeout::Extensions
2
2
  ===================
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/timeout-extensions.svg)](http://rubygems.org/gems/timeout-extensions)
5
+ [![Build Status](https://secure.travis-ci.org/celluloid/timeout-extensions.svg?branch=master)](http://travis-ci.org/celluloid/timeout-extensions)
6
+ [![Code Climate](https://codeclimate.com/github/celluloid/timeout-extensions.svg)](https://codeclimate.com/github/celluloid/timeout-extensions)
7
+
4
8
  The Timeout::Extensions Gem augments Ruby's `timeout.rb` API with support for
5
9
  multiple timeout backends which can be mixed and matched within a single app.
6
10
 
@@ -71,6 +75,18 @@ Timeout.backend(MyTimeoutThingy) do
71
75
  end
72
76
  ```
73
77
 
78
+ ## Supported Ruby Versions
79
+
80
+ This library aims to support and is [tested against][travis] the following Ruby
81
+ versions:
82
+
83
+ * Ruby 2.1
84
+ * Ruby 2.2
85
+ * Ruby 2.3
86
+ * JRuby 9.1
87
+
88
+ If something doesn't work on one of these versions, it's a bug.
89
+
74
90
  # Contributing
75
91
 
76
92
  * Fork this repository on github
@@ -80,5 +96,5 @@ end
80
96
 
81
97
  # License
82
98
 
83
- Copyright (c) 2014-2015 Tony Arcieri, Tiago Cardoso
99
+ Copyright (c) 2014-2016 Tony Arcieri, Tiago Cardoso
84
100
  Distributed under the MIT License. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new
5
+
6
+ require "rubocop/rake_task"
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: %w(spec rubocop)
@@ -1,45 +1,50 @@
1
- require 'timeout/extensions/version'
1
+ require "timeout/extensions/version"
2
2
 
3
+ # Core extensions to Thread
4
+ #
5
+ # Adds accessors to customize timeout and sleep within a thread,
6
+ # if you have a better friendlier implementation of both methods,
7
+ # or if your code breaks with the stdlib implementations.
8
+ #
3
9
  class Thread
4
10
  attr_accessor :timeout_handler
5
11
  attr_accessor :sleep_handler
6
12
  end
7
13
 
8
14
  module Timeout::Extensions
9
- def self.extended(mod)
10
- mod.singleton_class.class_eval do
11
- alias_method :timeout_without_handler, :timeout
12
- alias_method :timeout, :timeout_with_handler
15
+ module TimeoutMethods
16
+ def timeout(*args, &block)
17
+ if (timeout_handler = Thread.current.timeout_handler)
18
+ timeout_handler.call(*args, &block)
19
+ else
20
+ super
21
+ end
13
22
  end
14
23
  end
15
24
 
16
- def timeout_with_handler(*args, &block)
17
- if timeout_handler = Thread.current.timeout_handler
18
- timeout_handler.call(*args, &block)
19
- else
20
- timeout_without_handler(*args, &block)
25
+ module KernelMethods
26
+ def sleep(*args)
27
+ if (sleep_handler = Thread.current.sleep_handler)
28
+ sleep_handler.call(*args)
29
+ else
30
+ super
31
+ end
21
32
  end
22
33
  end
23
- module_function :timeout_with_handler
24
- public :timeout_with_handler
25
- end
26
34
 
27
- module Kernel::Extensions
28
- def self.included(mod)
29
- mod.class_eval do
30
- alias_method :sleep_without_handler, :sleep
31
- alias_method :sleep, :sleep_with_handler
32
- end
35
+ # in order for prepend to work, I have to do it in the Timeout module singleton class
36
+ class << ::Timeout
37
+ prepend TimeoutMethods
33
38
  end
34
39
 
35
- def sleep_with_handler(*args)
36
- if sleep_handler = Thread.current.sleep_handler
37
- sleep_handler.call(*args)
38
- else
39
- sleep_without_handler(*args)
40
- end
40
+ # ditto for Kernel
41
+ class << ::Kernel
42
+ prepend KernelMethods
41
43
  end
42
- end
43
44
 
44
- Timeout.extend Timeout::Extensions
45
- include Kernel::Extensions
45
+ # this is an hack so that calling "sleep(2)" works. Amazingly, the message doesn't get
46
+ # sent to Kernel.sleep code path.
47
+ # https://bugs.ruby-lang.org/issues/12535
48
+ #
49
+ ::Object.prepend KernelMethods
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Timeout::Extensions
2
- VERSION = "0.0.0"
2
+ VERSION = "0.1.0".freeze
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,65 +1,22 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'logger'
4
- require 'timeout'
5
- require 'timeout/extensions'
6
- require 'celluloid/autostart'
7
- require 'celluloid/rspec'
8
-
9
- logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a')
10
- logfile.sync = true
11
-
12
- logger = Celluloid.logger = Logger.new(logfile)
13
-
14
- Celluloid.shutdown_timeout = 1
15
-
16
-
17
- class Celluloid::Actor
18
- # Important that these two are left out, or else
19
- # timeout calls inside the actor scope will never propagate
20
- # to the proper extensions
21
- # TODO: eventually remove this if celluloid adopts the gem
22
- undef_method :timeout if instance_methods(false).include?(:timeout)
23
- undef_method :sleep if instance_methods(false).include?(:sleep)
24
- end
25
-
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "logger"
4
+ require "timeout"
5
+ require "timeout/extensions"
26
6
 
27
7
  RSpec.configure do |config|
28
- config.treat_symbols_as_metadata_keys_with_true_values = true
29
8
  config.run_all_when_everything_filtered = true
30
9
  config.filter_run :focus
31
10
 
32
11
  config.before do
33
- Celluloid.logger = logger
34
- if Celluloid.running?
35
- Celluloid.shutdown
36
- sleep 0.01
37
- Celluloid.internal_pool.assert_inactive
38
- end
39
-
40
- Celluloid.boot
41
-
42
- FileUtils.rm("/tmp/cell_sock") if File.exist?("/tmp/cell_sock")
43
12
  include Timeout::Extensions
44
13
  end
45
14
 
46
- config.order = 'random'
15
+ config.order = "random"
47
16
  end
48
17
 
49
- class ExampleActor
50
- include Celluloid
51
- execute_block_on_receiver :wrap
52
-
53
- def wrap
18
+ def within_thread
19
+ Thread.new do
54
20
  yield
55
- end
21
+ end.join
56
22
  end
57
-
58
- def within_actor(&block)
59
- actor = ExampleActor.new
60
- actor.wrap(&block)
61
- ensure
62
- actor.terminate if actor and actor.alive?
63
- end
64
-
65
-
@@ -1,35 +1,31 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe Timeout::Extensions do
4
- describe "timeout" do
3
+ RSpec.describe Timeout::Extensions do
4
+ describe ".timeout" do
5
5
  let(:dummy_timeout) { double(:meta_timeout) }
6
6
  let(:exception) { double(:exception) }
7
- let(:action) { Proc.new{ |t| } }
8
- context "inside and outside of actor" do
7
+ let(:action) { proc { |t| } }
8
+ context "inside and outside of thread" do
9
9
  it "hits the proper timeout handler" do
10
- within_actor do
10
+ within_thread do
11
11
  Thread.current.timeout_handler = dummy_timeout
12
12
  expect(dummy_timeout).to receive(:call).with(2, exception, &action)
13
13
  timeout(2, exception, &action)
14
14
  end
15
- expect(Timeout).to receive(:timeout_without_handler)
16
- timeout(2, exception, &action)
17
15
  end
18
16
  end
19
17
  end
20
18
 
21
- describe "sleep" do
19
+ describe ".sleep" do
22
20
  let(:dummy_sleep) { double(:meta_sleep) }
23
- context "inside and outside of actor" do
21
+ context "inside and outside of thread" do
24
22
  it "hits the proper sleep handler" do
25
- within_actor do
23
+ within_thread do
26
24
  Thread.current.sleep_handler = dummy_sleep
27
25
  expect(dummy_sleep).to receive(:call).with(2)
28
26
  sleep(2)
29
27
  end
30
- expect(self).to receive(:sleep_without_handler)
31
- sleep(2)
32
28
  end
33
29
  end
34
- end
30
+ end
35
31
  end
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'timeout/extensions/version'
4
+ require "timeout/extensions/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "timeout-extensions"
@@ -18,8 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "rake", "~> 10.4.2"
22
- spec.add_development_dependency "pry", "~> 0.10.1"
23
- spec.add_development_dependency "rspec", "~> 2.14.0"
24
- spec.add_development_dependency "celluloid", ">= 0.16.0"
21
+ spec.required_ruby_version = ">= 2.0.0"
25
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeout-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -9,64 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-22 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: 10.4.2
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: 10.4.2
28
- - !ruby/object:Gem::Dependency
29
- name: pry
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: 0.10.1
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: 0.10.1
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 2.14.0
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 2.14.0
56
- - !ruby/object:Gem::Dependency
57
- name: celluloid
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.16.0
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.16.0
12
+ date: 2016-07-03 00:00:00.000000000 Z
13
+ dependencies: []
70
14
  description: A timeout extension for Ruby which plugs into multiple timeout backends
71
15
  email:
72
16
  - bascule@gmail.com
@@ -76,6 +20,9 @@ extra_rdoc_files: []
76
20
  files:
77
21
  - ".gitignore"
78
22
  - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".travis.yml"
25
+ - CHANGES.md
79
26
  - Gemfile
80
27
  - LICENSE.txt
81
28
  - README.md
@@ -98,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
45
  requirements:
99
46
  - - ">="
100
47
  - !ruby/object:Gem::Version
101
- version: '0'
48
+ version: 2.0.0
102
49
  required_rubygems_version: !ruby/object:Gem::Requirement
103
50
  requirements:
104
51
  - - ">="
@@ -106,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
53
  version: '0'
107
54
  requirements: []
108
55
  rubyforge_project:
109
- rubygems_version: 2.4.5
56
+ rubygems_version: 2.5.1
110
57
  signing_key:
111
58
  specification_version: 4
112
59
  summary: Extensions to the Ruby standard library's timeout API