wsdirector-cli 0.4.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 +4 -4
- data/CHANGELOG.md +78 -0
- data/LICENSE.txt +1 -1
- data/README.md +238 -42
- metadata +18 -164
- data/bin/wsdirector +0 -15
- data/lib/wsdirector/cli.rb +0 -78
- data/lib/wsdirector/client.rb +0 -66
- data/lib/wsdirector/clients_holder.rb +0 -23
- data/lib/wsdirector/configuration.rb +0 -24
- data/lib/wsdirector/ext/deep_dup.rb +0 -34
- data/lib/wsdirector/printer.rb +0 -11
- data/lib/wsdirector/protocols/action_cable.rb +0 -75
- data/lib/wsdirector/protocols/base.rb +0 -135
- data/lib/wsdirector/protocols.rb +0 -28
- data/lib/wsdirector/result.rb +0 -56
- data/lib/wsdirector/results_holder.rb +0 -48
- data/lib/wsdirector/runner.rb +0 -45
- data/lib/wsdirector/scenario_reader.rb +0 -77
- data/lib/wsdirector/task.rb +0 -47
- data/lib/wsdirector/utils.rb +0 -15
- data/lib/wsdirector/version.rb +0 -5
- data/lib/wsdirector-cli.rb +0 -3
- data/lib/wsdirector.rb +0 -23
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "erb"
|
4
|
-
|
5
|
-
module WSDirector
|
6
|
-
# Read and parse YAML scenario
|
7
|
-
class ScenarioReader
|
8
|
-
class << self
|
9
|
-
include WSDirector::Utils
|
10
|
-
|
11
|
-
def parse(file_path)
|
12
|
-
contents = ::YAML.load(ERB.new(File.read(file_path)).result) # rubocop:disable Security/YAMLLoad
|
13
|
-
|
14
|
-
if contents.first.key?("client")
|
15
|
-
parse_multiple_scenarios(contents)
|
16
|
-
else
|
17
|
-
{"total" => 1, "clients" => [parse_simple_scenario(contents)]}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def handle_steps(steps)
|
24
|
-
steps.flat_map.with_index do |step, id|
|
25
|
-
if step.is_a?(Hash)
|
26
|
-
type, data = step.to_a.first
|
27
|
-
|
28
|
-
data["sample"] = [1, parse_multiplier(data["sample"])].max if data["sample"]
|
29
|
-
|
30
|
-
multiplier = parse_multiplier(data.delete("multiplier") || "1")
|
31
|
-
Array.new(multiplier) { {"type" => type, "id" => id}.merge(data) }
|
32
|
-
else
|
33
|
-
{"type" => step, "id" => id}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_simple_scenario(
|
39
|
-
steps,
|
40
|
-
multiplier: 1, name: "default", ignore: nil, protocol: "base"
|
41
|
-
)
|
42
|
-
{
|
43
|
-
"multiplier" => multiplier,
|
44
|
-
"steps" => handle_steps(steps),
|
45
|
-
"name" => name,
|
46
|
-
"ignore" => ignore,
|
47
|
-
"protocol" => protocol
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
def parse_multiple_scenarios(definitions)
|
52
|
-
total_count = 0
|
53
|
-
clients = definitions.map.with_index do |client, i|
|
54
|
-
_, client = client.to_a.first
|
55
|
-
multiplier = parse_multiplier(client.delete("multiplier") || "1")
|
56
|
-
name = client.delete("name") || (i + 1).to_s
|
57
|
-
total_count += multiplier
|
58
|
-
ignore = parse_ingore(client.fetch("ignore", nil))
|
59
|
-
parse_simple_scenario(
|
60
|
-
client.fetch("actions", []),
|
61
|
-
multiplier: multiplier,
|
62
|
-
name: name,
|
63
|
-
ignore: ignore,
|
64
|
-
protocol: client.fetch("protocol", "base")
|
65
|
-
)
|
66
|
-
end
|
67
|
-
{"total" => total_count, "clients" => clients}
|
68
|
-
end
|
69
|
-
|
70
|
-
def parse_ingore(str)
|
71
|
-
return unless str
|
72
|
-
|
73
|
-
Array(str)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/lib/wsdirector/task.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "wsdirector/client"
|
4
|
-
require "wsdirector/protocols"
|
5
|
-
|
6
|
-
module WSDirector
|
7
|
-
# Single client operator
|
8
|
-
class Task
|
9
|
-
attr_reader :global_holder, :client
|
10
|
-
|
11
|
-
def initialize(config, global_holder:, result:)
|
12
|
-
@ignore = config.fetch("ignore")
|
13
|
-
@steps = config.fetch("steps")
|
14
|
-
@global_holder = global_holder
|
15
|
-
@result = result
|
16
|
-
|
17
|
-
protocol_class = Protocols.get(config.fetch("protocol", "base"))
|
18
|
-
@protocol = protocol_class.new(self)
|
19
|
-
end
|
20
|
-
|
21
|
-
def run
|
22
|
-
connect!
|
23
|
-
|
24
|
-
steps.each(&protocol)
|
25
|
-
|
26
|
-
result.succeed
|
27
|
-
rescue Error => e
|
28
|
-
result.failed(e.message)
|
29
|
-
end
|
30
|
-
|
31
|
-
def sampled?(step)
|
32
|
-
return true unless step["sample"]
|
33
|
-
|
34
|
-
id, max = step["id"], step["sample"]
|
35
|
-
|
36
|
-
result.track_sample(id, max)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
attr_reader :steps, :result, :protocol
|
42
|
-
|
43
|
-
def connect!
|
44
|
-
protocol.init_client(ignore: @ignore)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/wsdirector/utils.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module WSDirector
|
4
|
-
module Utils # :nodoc:
|
5
|
-
MULTIPLIER_FORMAT = /^[-+*\/\\\d ]+$/
|
6
|
-
|
7
|
-
def parse_multiplier(str)
|
8
|
-
prepared = str.to_s.gsub(":scale", WSDirector.config.scale.to_s)
|
9
|
-
raise WSDirector::Error, "Unknown multiplier format: #{str}" unless
|
10
|
-
MULTIPLIER_FORMAT.match?(prepared)
|
11
|
-
|
12
|
-
eval(prepared) # rubocop:disable Security/Eval
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/wsdirector/version.rb
DELETED
data/lib/wsdirector-cli.rb
DELETED
data/lib/wsdirector.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "concurrent"
|
4
|
-
require "yaml"
|
5
|
-
require "json"
|
6
|
-
|
7
|
-
require "wsdirector/version"
|
8
|
-
require "wsdirector/configuration"
|
9
|
-
require "wsdirector/utils"
|
10
|
-
|
11
|
-
# Command line tool for testing websocket servers using scenarios.
|
12
|
-
module WSDirector
|
13
|
-
class Error < StandardError
|
14
|
-
end
|
15
|
-
|
16
|
-
class << self
|
17
|
-
def config
|
18
|
-
@config ||= Configuration.new
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
require "wsdirector/cli"
|