sus-fixtures-async 0.1.4 → 0.2.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
  SHA256:
3
- metadata.gz: d99d77fb7f3fe87e81ab665ad4689bb3281dc8c14bcac5ad7e9f58cd45ac9487
4
- data.tar.gz: a2c6eb004e55bcf7ce0a1a19c832d9bbc4b2076b6f0813133cd870c15565cb34
3
+ metadata.gz: e0f93349ce0e3cfae2ab926d9e9196839cf8ae715f446355531fff5f7613a2f9
4
+ data.tar.gz: e7f80e88e911fb2c90289eded998b6ff413591766d7f5505ebdffad963df777e
5
5
  SHA512:
6
- metadata.gz: 3ecedf1af0d606daf679583ae999757fad815b117239b512293fe2ff52395d7032c4ce4b224d37651ade32cbd459cf727182eff7746eae9dc5a56562179df7cb
7
- data.tar.gz: aa34a76a090aa4d7a66a21f8b5592310c42dea5d58973b87c3f9462261bf6730a7d5d87b85fa2f7531c15583b9fed1426671aea8bf491991dade8e6cf8220c7c
6
+ metadata.gz: 0f2b464e361a0f6c78aca01ca26925b5e80a46ac53d0926076788bdd725290343b0a3b8f648014071dcdc9ff680d60578621daea0e09fbacaccd349cbac1eb4b
7
+ data.tar.gz: 2bdc028ac0ca0f9bbe66a6e12db20411aefb02265f7bb6f6ae9dce5ab4e78875171788cb1072afa590ab04fcd1b5d730cb8532d3abf7ab7e05b5c85e233ce62e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,74 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2023, by Samuel Williams.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
- require 'async'
7
- require 'sus/fixtures'
6
+ require_relative 'scheduler_context'
8
7
 
9
8
  module Sus::Fixtures::Async
10
- module ReactorContext
11
- def run_with_timeout(timeout = nil, &block)
12
- task = ::Async::Task.current
13
-
14
- result = nil
15
- timer_task = nil
16
-
17
- if timeout
18
- timer_task = task.async(transient: true) do |task|
19
- # Wait for the timeout, at any point this task might be cancelled if the user code completes:
20
- task.annotate("Timer task timeout=#{timeout}.")
21
- task.sleep(timeout)
22
-
23
- # The timeout expired, so generate an error:
24
- buffer = StringIO.new
25
- task.reactor.print_hierarchy(buffer)
26
-
27
- # Raise an error so it is logged:
28
- raise Async::TimeoutError, "Run time exceeded timeout #{timeout}s:\n#{buffer.string}"
29
- end
30
- end
31
-
32
- spec_task = task.async do |spec_task|
33
- spec_task.annotate("running example")
34
-
35
- begin
36
- result = yield(spec_task)
37
- ensure
38
- # We are finished, so stop the timer task if it was started:
39
- timer_task&.stop
40
- end
41
-
42
- # Now stop the entire reactor:
43
- raise Async::Stop
44
- end
45
-
46
- begin
47
- timer_task&.wait
48
- spec_task.wait
49
- ensure
50
- spec_task.stop
51
- end
52
-
53
- return result
54
- end
55
-
56
- def timeout
57
- 60
58
- end
59
-
60
- def reactor
61
- Async::Task.current.reactor
62
- end
63
-
64
- def around(&block)
65
- Sync do |task|
66
- task.annotate(self.class)
67
-
68
- run_with_timeout(self.timeout) do
69
- super(&block)
70
- end
71
- end
72
- end
73
- end
9
+ ReactorContext = SchedulerContext
74
10
  end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2024, by Samuel Williams.
5
+
6
+ require 'async'
7
+ require 'sus/fixtures'
8
+
9
+ module Sus::Fixtures::Async
10
+ module SchedulerContext
11
+ def run_with_timeout(timeout = nil, &block)
12
+ task = ::Async::Task.current
13
+
14
+ result = nil
15
+ timer_task = nil
16
+
17
+ if timeout
18
+ timer_task = task.async(transient: true) do |task|
19
+ # Wait for the timeout, at any point this task might be cancelled if the user code completes:
20
+ task.annotate("Timer task timeout=#{timeout}.")
21
+ task.sleep(timeout)
22
+
23
+ # The timeout expired, so generate an error:
24
+ buffer = StringIO.new
25
+ scheduler.print_hierarchy(buffer)
26
+
27
+ # Raise an error so it is logged:
28
+ raise Async::TimeoutError, "Run time exceeded timeout #{timeout}s:\n#{buffer.string}"
29
+ end
30
+ end
31
+
32
+ spec_task = task.async do |spec_task|
33
+ spec_task.annotate("running example")
34
+
35
+ begin
36
+ result = yield(spec_task)
37
+ ensure
38
+ # We are finished, so stop the timer task if it was started:
39
+ timer_task&.stop
40
+ end
41
+
42
+ # Now stop the scheduler:
43
+ raise Async::Stop
44
+ end
45
+
46
+ begin
47
+ timer_task&.wait
48
+ spec_task.wait
49
+ ensure
50
+ spec_task.stop
51
+ end
52
+
53
+ return result
54
+ end
55
+
56
+ def timeout
57
+ 60
58
+ end
59
+
60
+ def scheduler
61
+ Fiber.scheduler
62
+ end
63
+
64
+ alias reactor scheduler
65
+
66
+ def around(&block)
67
+ Sync do |task|
68
+ task.annotate(self.class)
69
+
70
+ run_with_timeout(self.timeout) do
71
+ # This ensures all before/after blocks are also run in the scheduler context.
72
+ super(&block)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022-2023, by Samuel Williams.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
6
  module Sus
7
7
  module Fixtures
8
8
  module Async
9
- VERSION = "0.1.4"
9
+ VERSION = "0.2.0"
10
10
  end
11
11
  end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2022-2024, by Samuel Williams.
5
5
 
6
6
  require_relative 'async/version'
7
7
  require_relative 'async/reactor_context'
data/readme.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Provides a convenient fixture for testing async components in a reactor.
4
4
 
5
- [![Development Status](https://github.com/socketry/sus-fixtures-async/workflows/Test/badge.svg)](https://github.com/socketry/sus-fixtures-async/actions?workflow=Test)
5
+ [![Development Status](https://github.com/suspecting/sus-fixtures-async/workflows/Test/badge.svg)](https://github.com/suspecting/sus-fixtures-async/actions?workflow=Test)
6
6
 
7
7
  ## Usage
8
8
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus-fixtures-async
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -37,7 +37,7 @@ cert_chain:
37
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
38
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
39
39
  -----END CERTIFICATE-----
40
- date: 2024-07-23 00:00:00.000000000 Z
40
+ date: 2024-08-18 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: async
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - lib/sus/fixtures/async.rb
77
77
  - lib/sus/fixtures/async/reactor_context.rb
78
+ - lib/sus/fixtures/async/scheduler_context.rb
78
79
  - lib/sus/fixtures/async/version.rb
79
80
  - license.md
80
81
  - readme.md
metadata.gz.sig CHANGED
Binary file