thread_order 0.1.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a2dabe6630ddb96b43c686369e6a50f85a1d55c
4
- data.tar.gz: aa1928df61b660fec67fbd4d33eb3f8214c8aefb
3
+ metadata.gz: b2d68b153c8a232b3fdcb3efc2ec6799abf9e11a
4
+ data.tar.gz: 5f340011a9259a523b6fa3dca0494ad8f17887aa
5
5
  SHA512:
6
- metadata.gz: b33ae8eafd3294c2f030f91e29268818eb5f1ec22f34a8e564b3731075033ba7c53dc6df07861932343e68858d3abf0d0e45a74bfdd2665e0cd6b9ebbdccbc81
7
- data.tar.gz: a83df4acfce7b1d39bff123261b7ab12e0e8dc4cc35af6f973de76469873656f508360242427ea9c9f216b3d16fd4ae6056298e60d82709efc09c35bbf688c49
6
+ metadata.gz: 6247a9d7f485371a1725e7098a2dde38b4376a822ecfcb6ea7a69c36d8a1abc7d60bded9f12c3c5297bd635c05e4c87c271bc73054f19724068e2f2a62ed979c
7
+ data.tar.gz: 988632f09cc15d15fa705e87a561d86b26c8f5f079df692c8d288865cd578674f1db67371e8363e08e66adc59ce778b6bdc3a91ea9e74a9cc7de2f126c828591
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  Gemfile.lock
3
+ tmp/
@@ -1,8 +1,20 @@
1
1
  language: ruby
2
- script: bundle exec rspec
2
+ script: spec/run
3
3
  rvm:
4
+ - 1.8.7
5
+ - 1.9.2
4
6
  - 1.9.3
5
7
  - 2.0.0
6
- - 2.1.2
7
- - 2.2.0
8
+ - 2.1
9
+ - 2.2
8
10
  - ruby-head
11
+ - ree
12
+ - jruby-18mode
13
+ - jruby
14
+ - jruby-head
15
+ - rbx
16
+ matrix:
17
+ include:
18
+ - rvm: jruby
19
+ env: JRUBY_OPTS='--2.0'
20
+ fast_finish: true
data/Readme.md CHANGED
@@ -1,2 +1,11 @@
1
+ [![Build Status](https://travis-ci.org/JoshCheek/thread_order.svg)](https://travis-ci.org/JoshCheek/thread_order)
2
+
1
3
  ThreadOrder
2
4
  ===========
5
+
6
+ A tool for testing threaded code.
7
+ Its purpose is to enable reasoning about thread order.
8
+
9
+ * Tested on 1.8.7 - 2.2, JRuby, Rbx
10
+ * It has no external dependencies
11
+ * It does not depend on the stdlib.
@@ -1,3 +1,5 @@
1
+ require 'thread_order/mutex'
2
+
1
3
  class ThreadOrder
2
4
  def initialize
3
5
  @bodies = {}
@@ -0,0 +1,60 @@
1
+ # On > 1.9, this is in core.
2
+ # On 1.8.7, it's in the stdlib.
3
+ # We don't want to load the stdlib, b/c this is a test tool, and can affect the test environment,
4
+ # causing tests to pass where they should fail.
5
+ #
6
+ # So we're transcribing it here, from.
7
+ # It is based on this implementation: https://github.com/ruby/ruby/blob/v1_8_7_374/lib/thread.rb#L56
8
+ # If it's not already defined. Some methods we don't need are deleted.
9
+ # Anything I don't understand is left in.
10
+ class ThreadOrder
11
+ Mutex = if defined? ::Mutex
12
+ ::Mutex
13
+ else
14
+ Class.new do
15
+ def initialize
16
+ @waiting = []
17
+ @locked = false;
18
+ @waiting.taint # enable tainted comunication
19
+ self.taint
20
+ end
21
+
22
+ def lock
23
+ while (Thread.critical = true; @locked)
24
+ @waiting.push Thread.current
25
+ Thread.stop
26
+ end
27
+ @locked = true
28
+ Thread.critical = false
29
+ self
30
+ end
31
+
32
+ def unlock
33
+ return unless @locked
34
+ Thread.critical = true
35
+ @locked = false
36
+ begin
37
+ t = @waiting.shift
38
+ t.wakeup if t
39
+ rescue ThreadError
40
+ retry
41
+ end
42
+ Thread.critical = false
43
+ begin
44
+ t.run if t
45
+ rescue ThreadError
46
+ end
47
+ self
48
+ end
49
+
50
+ def synchronize
51
+ lock
52
+ begin
53
+ yield
54
+ ensure
55
+ unlock
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ class ThreadOrder
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,58 @@
1
+ #!/bin/bash
2
+
3
+ # do this stuff in a tmp dir
4
+ cd "$(dirname "$0")/.."
5
+ project_root=`pwd`
6
+ mkdir -p tmp
7
+ cd tmp
8
+
9
+ # this is basically a shitty version of `gem unpack`
10
+ get_gem() {
11
+ name="$1"
12
+ url="$2"
13
+
14
+ if test -d "$name"
15
+ then
16
+ echo "Skipping download of $name"
17
+ return
18
+ else
19
+ echo "Downloading $name"
20
+ fi
21
+
22
+ mkdir "$name" &&
23
+ cd "$name" &&
24
+ curl -L "$url" > "$name".gem &&
25
+ tar -xf "$name".gem &&
26
+ gunzip data.tar.gz &&
27
+ tar -xf data.tar &&
28
+ cd ..
29
+ }
30
+
31
+ # download dependencies
32
+ get_gem "rspec" "https://rubygems.org/downloads/rspec-3.2.0.gem" &&
33
+ get_gem "rspec-core" "https://rubygems.org/downloads/rspec-core-3.2.1.gem" &&
34
+ get_gem "rspec-support" "https://rubygems.org/downloads/rspec-support-3.2.2.gem" &&
35
+ get_gem "rspec-expectations" "https://rubygems.org/downloads/rspec-expectations-3.2.0.gem" &&
36
+ get_gem "rspec-mocks" "https://rubygems.org/downloads/rspec-mocks-3.2.1.gem" &&
37
+ get_gem "diff-lcs" "https://rubygems.org/downloads/diff-lcs-1.2.5.gem"
38
+
39
+
40
+ # run specs
41
+ cd $project_root
42
+
43
+ export PATH="$project_root/tmp/rspec-core/exe:$PATH"
44
+
45
+ opts=""
46
+ opts=" -I $project_root/tmp/diff-lcs/lib $opts"
47
+ opts=" -I $project_root/tmp/rspec/lib $opts"
48
+ opts=" -I $project_root/tmp/rspec-core/lib $opts"
49
+ opts=" -I $project_root/tmp/rspec-expectations/lib $opts"
50
+ opts=" -I $project_root/tmp/rspec-mocks/lib $opts"
51
+ opts=" -I $project_root/tmp/rspec-support/lib $opts"
52
+
53
+ if `ruby -e "exit RUBY_VERSION != '1.8.7'"`
54
+ then
55
+ opts="--disable-gems $opts"
56
+ fi
57
+
58
+ ruby $opts -S rspec
@@ -102,12 +102,16 @@ RSpec.describe ThreadOrder do
102
102
  expect(thread_names).to eq [:a, nil]
103
103
  end
104
104
 
105
- xit 'is implemented without depending on the stdlib' do
105
+ it 'is implemented without depending on the stdlib' do
106
106
  loaded_filenames = $LOADED_FEATURES.map { |filepath| File.basename filepath }
107
- pending 'fucking fails :('
108
- expect(loaded_filenames).to_not include 'monitor.rb'
109
- expect(loaded_filenames).to_not include 'thread.rb'
110
- expect(loaded_filenames).to_not include 'thread.bundle'
107
+ begin
108
+ expect(loaded_filenames).to_not include 'monitor.rb'
109
+ expect(loaded_filenames).to_not include 'thread.rb'
110
+ expect(loaded_filenames).to_not include 'thread.bundle'
111
+ rescue RSpec::Expectations::ExpectationNotMetError
112
+ pending if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' # somehow this still gets loaded in some JRubies
113
+ raise
114
+ end
111
115
  end
112
116
 
113
117
  describe 'incorrect interface usage' do
@@ -1,9 +1,11 @@
1
+ require_relative 'lib/thread_order/version'
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'thread_order'
3
- s.version = '0.1.0'
5
+ s.version = ThreadOrder::VERSION
4
6
  s.licenses = ['MIT']
5
- s.summary = "Test helper for ordering threaded code (does not depend on stdlib)"
6
- s.description = "Test helper for ordering threaded code (does not depend on stdlib)."
7
+ s.summary = "Test helper for ordering threaded code"
8
+ s.description = "Test helper for ordering threaded code (does not depend on gems or stdlib, tested on 1.8.7 - 2.2)."
7
9
  s.authors = ["Josh Cheek"]
8
10
  s.email = 'josh.cheek@gmail.com'
9
11
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thread_order
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-28 00:00:00.000000000 Z
11
+ date: 2015-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -24,7 +24,8 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
- description: Test helper for ordering threaded code (does not depend on stdlib).
27
+ description: Test helper for ordering threaded code (does not depend on gems or stdlib,
28
+ tested on 1.8.7 - 2.2).
28
29
  email: josh.cheek@gmail.com
29
30
  executables: []
30
31
  extensions: []
@@ -36,6 +37,9 @@ files:
36
37
  - License.txt
37
38
  - Readme.md
38
39
  - lib/thread_order.rb
40
+ - lib/thread_order/mutex.rb
41
+ - lib/thread_order/version.rb
42
+ - spec/run
39
43
  - spec/thread_order_spec.rb
40
44
  - thread_order.gemspec
41
45
  homepage: https://github.com/JoshCheek/thread_order
@@ -58,10 +62,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
62
  version: '0'
59
63
  requirements: []
60
64
  rubyforge_project:
61
- rubygems_version: 2.4.1
65
+ rubygems_version: 2.4.5
62
66
  signing_key:
63
67
  specification_version: 4
64
- summary: Test helper for ordering threaded code (does not depend on stdlib)
68
+ summary: Test helper for ordering threaded code
65
69
  test_files:
70
+ - spec/run
66
71
  - spec/thread_order_spec.rb
67
72
  has_rdoc: