integration-diff 0.0.3 → 0.1.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/Readme.md +10 -0
- data/lib/integration_diff/runner.rb +12 -31
- data/lib/integration_diff/uploader.rb +13 -0
- data/lib/integration_diff/uploaders/concurrent.rb +38 -0
- data/lib/integration_diff/uploaders/sequential.rb +22 -0
- data/lib/integration_diff/utils.rb +29 -0
- data/lib/integration_diff/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97cfcbbd84c5a7bc1b00555ea38c2437d26303ae
|
4
|
+
data.tar.gz: 9337a1a04ecf3b7e95f7a92a647f5aad83d0d886
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d16826719150fe1768d51bb968b1a97c18ab793a08b0ce156ef12f0bded4ca0eaeef8e39cc116f648882ac3cd02ad1f9f5d8db0e04708b1d79c630782bd506d0
|
7
|
+
data.tar.gz: b53301ceadb3023d6f0be26ab4263bd296011e1f81bed949d4f5a18c45e657c653430994b72d5cc4377c5d2ca765d5314b94f7b64d07d3a3aa74084f64774db9
|
data/Readme.md
CHANGED
@@ -73,3 +73,13 @@ describe "Landing page" do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
```
|
76
|
+
|
77
|
+
### Concurrency
|
78
|
+
|
79
|
+
By default, when all the screenshots are collected, and before suite ends, this
|
80
|
+
gem will upload all the screenshots taken. `IntegrationDiff.wrap_run` is the
|
81
|
+
method responsible for the same.
|
82
|
+
|
83
|
+
However, if you want to upload screenshots as and when they are taken, this gem
|
84
|
+
has soft dependency on `concurrent-ruby` gem. Make sure that this gem is
|
85
|
+
**required** before capturing screenshots, and see the magic yourself :)
|
@@ -1,32 +1,31 @@
|
|
1
1
|
require 'time'
|
2
2
|
require 'json'
|
3
3
|
require 'integration_diff/run_details'
|
4
|
+
require 'integration_diff/uploader'
|
5
|
+
require 'integration_diff/utils'
|
4
6
|
|
5
7
|
module IntegrationDiff
|
6
8
|
class Runner
|
7
9
|
include Capybara::DSL
|
8
10
|
|
9
|
-
DIR = 'tmp/idiff_images'.freeze
|
10
|
-
|
11
11
|
def self.instance
|
12
|
-
@runner ||= Runner.new(IntegrationDiff.
|
13
|
-
IntegrationDiff.project_name,
|
12
|
+
@runner ||= Runner.new(IntegrationDiff.project_name,
|
14
13
|
IntegrationDiff.javascript_driver)
|
15
14
|
end
|
16
15
|
|
17
|
-
def initialize(
|
18
|
-
@base_uri = base_uri
|
16
|
+
def initialize(project_name, javascript_driver)
|
19
17
|
@project_name = project_name
|
20
18
|
@javascript_driver = javascript_driver
|
21
19
|
|
20
|
+
dir = IntegrationDiff::Utils.images_dir
|
22
21
|
Dir.mkdir('tmp') unless Dir.exist?('tmp')
|
23
|
-
Dir.mkdir(
|
22
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
24
23
|
end
|
25
24
|
|
26
25
|
# TODO: Improve error handling here for network timeouts
|
27
26
|
def start_run
|
28
|
-
@identifiers = []
|
29
27
|
draft_run
|
28
|
+
@uploader = IntegrationDiff::Uploader.build(@run_id)
|
30
29
|
rescue StandardError => e
|
31
30
|
IntegrationDiff.logger.fatal e.message
|
32
31
|
raise e
|
@@ -34,9 +33,7 @@ module IntegrationDiff
|
|
34
33
|
|
35
34
|
# TODO: Improve error handling here for network timeouts
|
36
35
|
def wrap_run
|
37
|
-
@
|
38
|
-
upload_image(identifier)
|
39
|
-
end
|
36
|
+
@uploader.wrapup
|
40
37
|
|
41
38
|
complete_run if @run_id
|
42
39
|
rescue StandardError => e
|
@@ -45,9 +42,9 @@ module IntegrationDiff
|
|
45
42
|
end
|
46
43
|
|
47
44
|
def screenshot(identifier)
|
48
|
-
screenshot_name = image_file(identifier)
|
45
|
+
screenshot_name = IntegrationDiff::Utils.image_file(identifier)
|
49
46
|
page.save_screenshot(screenshot_name, full: true)
|
50
|
-
@
|
47
|
+
@uploader.enqueue(identifier)
|
51
48
|
end
|
52
49
|
|
53
50
|
private
|
@@ -58,7 +55,7 @@ module IntegrationDiff
|
|
58
55
|
details = IntegrationDiff::RunDetails.new.details
|
59
56
|
branch = details.branch
|
60
57
|
author = details.author
|
61
|
-
project =
|
58
|
+
project = @project_name
|
62
59
|
|
63
60
|
response = connection.post('/api/v1/runs',
|
64
61
|
name: run_name, project: project, group: branch,
|
@@ -67,28 +64,12 @@ module IntegrationDiff
|
|
67
64
|
@run_id = JSON.parse(response.body)["id"]
|
68
65
|
end
|
69
66
|
|
70
|
-
def upload_image(identifier)
|
71
|
-
IntegrationDiff.logger.fatal "uploading #{identifier}"
|
72
|
-
image_io = Faraday::UploadIO.new(image_file(identifier), 'image/png')
|
73
|
-
connection.post("/api/v1/runs/#{@run_id}/run_images",
|
74
|
-
identifier: identifier, image: image_io)
|
75
|
-
end
|
76
|
-
|
77
67
|
def complete_run
|
78
68
|
connection.put("/api/v1/runs/#{@run_id}/status", status: "completed")
|
79
69
|
end
|
80
70
|
|
81
|
-
def image_file(identifier)
|
82
|
-
"#{Dir.pwd}/#{DIR}/#{identifier}.png"
|
83
|
-
end
|
84
|
-
|
85
71
|
def connection
|
86
|
-
@
|
87
|
-
f.request :basic_auth, IntegrationDiff.api_key, 'X'
|
88
|
-
f.request :multipart
|
89
|
-
f.request :url_encoded
|
90
|
-
f.adapter :net_http
|
91
|
-
end
|
72
|
+
@connection ||= IntegrationDiff::Utils.connection
|
92
73
|
end
|
93
74
|
end
|
94
75
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module IntegrationDiff
|
2
|
+
class Uploader
|
3
|
+
def self.build(run_id)
|
4
|
+
if defined?(::Concurrent)
|
5
|
+
require 'integration_diff/uploaders/concurrent'
|
6
|
+
IntegrationDiff::Uploaders::Concurrent.new(run_id)
|
7
|
+
else
|
8
|
+
require 'integration_diff/uploaders/sequential'
|
9
|
+
IntegrationDiff::Uploaders::Sequential.new(run_id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'integration_diff/utils'
|
2
|
+
|
3
|
+
module IntegrationDiff
|
4
|
+
module Uploaders
|
5
|
+
class Concurrent
|
6
|
+
MAX_NO_OF_THREADS = 20
|
7
|
+
|
8
|
+
def initialize(run_id)
|
9
|
+
@run_id = run_id
|
10
|
+
@pool = ::Concurrent::FixedThreadPool.new(MAX_NO_OF_THREADS)
|
11
|
+
@screenshots_taken = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def enqueue(identifier)
|
15
|
+
@screenshots_taken += 1
|
16
|
+
|
17
|
+
@pool.post do
|
18
|
+
IntegrationDiff::Utils.upload_image(@run_id, identifier)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def wrapup
|
23
|
+
retries = 180 # 30 mins
|
24
|
+
|
25
|
+
# if all screenshots are not uploaded, wait.
|
26
|
+
until @screenshots_taken == @pool.completed_task_count
|
27
|
+
retries -= 1
|
28
|
+
break if retries.zero?
|
29
|
+
|
30
|
+
sleep 10
|
31
|
+
end
|
32
|
+
|
33
|
+
@pool.shutdown
|
34
|
+
@pool.wait_for_termination
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'integration_diff/utils'
|
2
|
+
|
3
|
+
module IntegrationDiff
|
4
|
+
module Uploaders
|
5
|
+
class Sequential
|
6
|
+
def initialize(run_id)
|
7
|
+
@run_id = run_id
|
8
|
+
@identifiers = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def enqueue(identifier)
|
12
|
+
@identifiers << identifier
|
13
|
+
end
|
14
|
+
|
15
|
+
def wrapup
|
16
|
+
@identifiers.each do |identifier|
|
17
|
+
IntegrationDiff::Utils.upload_image(@run_id, identifier)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module IntegrationDiff
|
2
|
+
module Utils
|
3
|
+
# http connection that will be used for uploading images
|
4
|
+
def self.connection
|
5
|
+
base_uri = IntegrationDiff.base_uri
|
6
|
+
Faraday.new(base_uri, request: { timeout: 120, open_timeout: 120 }) do |f|
|
7
|
+
f.request :basic_auth, IntegrationDiff.api_key, 'X'
|
8
|
+
f.request :multipart
|
9
|
+
f.request :url_encoded
|
10
|
+
f.adapter :net_http
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.images_dir
|
15
|
+
'tmp/idiff_images'.freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.upload_image(run_id, identifier)
|
19
|
+
IntegrationDiff.logger.fatal "uploading #{identifier}"
|
20
|
+
image_io = Faraday::UploadIO.new(image_file(identifier), 'image/png')
|
21
|
+
connection.post("/api/v1/runs/#{run_id}/run_images",
|
22
|
+
identifier: identifier, image: image_io)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.image_file(identifier)
|
26
|
+
"#{Dir.pwd}/#{images_dir}/#{identifier}.png"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: integration-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -40,6 +40,10 @@ files:
|
|
40
40
|
- lib/integration_diff/dummy_runner.rb
|
41
41
|
- lib/integration_diff/run_details.rb
|
42
42
|
- lib/integration_diff/runner.rb
|
43
|
+
- lib/integration_diff/uploader.rb
|
44
|
+
- lib/integration_diff/uploaders/concurrent.rb
|
45
|
+
- lib/integration_diff/uploaders/sequential.rb
|
46
|
+
- lib/integration_diff/utils.rb
|
43
47
|
- lib/integration_diff/version.rb
|
44
48
|
homepage: http://diff.codemancers.com
|
45
49
|
licenses:
|