sus-fixtures-async 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/sus/fixtures/async/reactor_context.rb +3 -67
- data/lib/sus/fixtures/async/scheduler_context.rb +77 -0
- data/lib/sus/fixtures/async/version.rb +2 -2
- data/lib/sus/fixtures/async.rb +2 -1
- data/license.md +1 -1
- data/readme.md +19 -14
- data.tar.gz.sig +0 -0
- metadata +8 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0f93349ce0e3cfae2ab926d9e9196839cf8ae715f446355531fff5f7613a2f9
|
4
|
+
data.tar.gz: e7f80e88e911fb2c90289eded998b6ff413591766d7f5505ebdffad963df777e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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-
|
4
|
+
# Copyright, 2022-2024, by Samuel Williams.
|
5
5
|
|
6
|
-
|
7
|
-
require 'sus/fixtures'
|
6
|
+
require_relative 'scheduler_context'
|
8
7
|
|
9
8
|
module Sus::Fixtures::Async
|
10
|
-
|
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-
|
4
|
+
# Copyright, 2022-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
module Sus
|
7
7
|
module Fixtures
|
8
8
|
module Async
|
9
|
-
VERSION = "0.
|
9
|
+
VERSION = "0.2.0"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/sus/fixtures/async.rb
CHANGED
data/license.md
CHANGED
data/readme.md
CHANGED
@@ -2,23 +2,28 @@
|
|
2
2
|
|
3
3
|
Provides a convenient fixture for testing async components in a reactor.
|
4
4
|
|
5
|
-
[![Development Status](https://github.com/
|
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
|
|
9
|
-
|
10
|
-
$ bundle add sus-fixtures-async
|
11
|
-
```
|
9
|
+
Please see the [project documentation](https://socketry.github.io/sus-fixtures-async/) for more details.
|
12
10
|
|
13
|
-
|
11
|
+
- [Getting Started](https://socketry.github.io/sus-fixtures-async/guides/getting-started/index) - This guide explains how to use the `sus-fixtures-async` gem to test async components in a reactor.
|
12
|
+
|
13
|
+
## Contributing
|
14
|
+
|
15
|
+
We welcome contributions to this project.
|
16
|
+
|
17
|
+
1. Fork it.
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
21
|
+
5. Create new Pull Request.
|
22
|
+
|
23
|
+
### Developer Certificate of Origin
|
14
24
|
|
15
|
-
|
16
|
-
include Sus::Fixtures::Async::ReactorContext
|
25
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
17
26
|
|
18
|
-
|
19
|
-
def timeout = 1
|
27
|
+
### Community Guidelines
|
20
28
|
|
21
|
-
|
22
|
-
expect(Async::Task.current).not.to be == nil
|
23
|
-
end
|
24
|
-
```
|
29
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
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.
|
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:
|
40
|
+
date: 2024-08-18 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: async
|
@@ -75,14 +75,17 @@ 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
|
81
|
-
homepage: https://github.com/
|
82
|
+
homepage: https://github.com/socketry/sus-fixtures-async
|
82
83
|
licenses:
|
83
84
|
- MIT
|
84
85
|
metadata:
|
86
|
+
documentation_uri: https://socketry.github.io/sus-fixtures-async/
|
85
87
|
funding_uri: https://github.com/sponsors/ioquatix/
|
88
|
+
source_code_uri: https://github.com/socketry/sus-fixtures-async.git
|
86
89
|
post_install_message:
|
87
90
|
rdoc_options: []
|
88
91
|
require_paths:
|
@@ -91,14 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
94
|
requirements:
|
92
95
|
- - ">="
|
93
96
|
- !ruby/object:Gem::Version
|
94
|
-
version: '3.
|
97
|
+
version: '3.1'
|
95
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
99
|
requirements:
|
97
100
|
- - ">="
|
98
101
|
- !ruby/object:Gem::Version
|
99
102
|
version: '0'
|
100
103
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.5.11
|
102
105
|
signing_key:
|
103
106
|
specification_version: 4
|
104
107
|
summary: Test fixtures for running in Async.
|
metadata.gz.sig
CHANGED
Binary file
|