flaky 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40c7fce2c960f2266e8f7e3f7931c875974b4b54
4
- data.tar.gz: c5e46bb2dbe776f720707543915ca8609f8d0afe
3
+ metadata.gz: 0f9ff093338f06bfed3fa22d003f989fab204700
4
+ data.tar.gz: 688ede60f2d512a8178c2ab01afddb582c80e598
5
5
  SHA512:
6
- metadata.gz: 9a0ad60c9f831be58811fb5d4d50e330c319ce76a3161c974621825cee3a69cb3fb8409069e265101116f30e7ced90ffe2c6737f30c7124d728cbd865fe313e8
7
- data.tar.gz: 6b437e86dc50c10d7ebf755040aa72a62517d99a840d961b3a74516e96b7dc6933d290c9808db841521b698a0259cf4eec591782dd139fda6e790012fe0410ea
6
+ metadata.gz: 6267bde8b466674dcc2fa27d37012a24de5b243a19c29c0f66f87096ba8429cb1378132a83d963722e5ba9c1ccc9dce71fc830fb615b532e80ea335235f64301
7
+ data.tar.gz: f12d59ff098bb2bacf1fc13c8cfbd6766e8acdd0936dc35375a1677f6cd61631aac41a9dd48329121dbbe0ec221cf0e05ab2a38462e73dad35e41cc04e8b0c8c
data/lib/flaky/appium.rb CHANGED
@@ -19,7 +19,8 @@ module Flaky
19
19
  #noinspection RubyResolve
20
20
  class Appium
21
21
  include POSIX::Spawn
22
- attr_reader :ready, :pid, :in, :out, :err, :log, :tail
22
+ # logcat is read & stopped by run.execute
23
+ attr_reader :ready, :pid, :in, :out, :err, :log, :tail, :logcat
23
24
  @@thread = nil
24
25
 
25
26
  def self.remove_ios_apps
@@ -46,17 +47,29 @@ module Flaky
46
47
  Process::waitpid(_pid) if _pid
47
48
  end
48
49
 
49
- def initialize
50
+ # android: true to activate Android mode
51
+ def initialize opts={}
50
52
  @ready = false
51
53
  @pid, @in, @out, @err = nil
52
54
  @log = ''
53
55
  @tail = nil
56
+ @android = opts.fetch(:android, false)
57
+ if @android
58
+ @droid = Flaky::Android.new
59
+ @logcat = Flaky::Logcat.new
60
+ end
54
61
  end
55
62
 
56
63
  def start
57
64
  @log = ''
58
65
  self.stop # stop existing process
59
- self.class.remove_ios_apps
66
+
67
+ if @android
68
+ @droid.reset
69
+ @logcat.start
70
+ else
71
+ self.class.remove_ios_apps
72
+ end
60
73
 
61
74
  @@thread.exit if @@thread
62
75
  @@thread = Thread.new do
@@ -102,6 +115,10 @@ module Flaky
102
115
  self.class.kill_all 'node'
103
116
  end
104
117
 
118
+ def end_all_instruments
119
+ self.class.kill_all 'instruments'
120
+ end
121
+
105
122
  # Invoked inside a thread by `self.go`
106
123
  def launch
107
124
  @log = ''
@@ -109,9 +126,9 @@ module Flaky
109
126
  @ready = false
110
127
  appium_home = ENV['APPIUM_HOME']
111
128
  raise "ENV['APPIUM_HOME'] must be set!" if appium_home.nil? || appium_home.empty?
112
- contains_appium = File.exists?(File.join(ENV['APPIUM_HOME'], 'server.js'))
113
- raise "Appium home `#{appium_home}` doesn't contain server.js!" unless contains_appium
114
- cmd = %Q(cd "#{appium_home}"; node server.js)
129
+ contains_appium = File.exists?(File.join(ENV['APPIUM_HOME'], 'bin', 'appium.js'))
130
+ raise "Appium home `#{appium_home}` doesn't contain bin/appium.js!" unless contains_appium
131
+ cmd = %Q(cd "#{appium_home}"; node .)
115
132
  @pid, @in, @out, @err = popen4 cmd
116
133
  @in.close
117
134
  self # used to chain `launch.wait`
@@ -122,11 +139,11 @@ module Flaky
122
139
  # https://github.com/tmm1/pygments.rb/blob/master/lib/pygments/popen.rb
123
140
  begin
124
141
  Process.kill 'KILL', @pid
125
- Process.waitpid @pid
126
142
  rescue
127
143
  end unless @pid.nil?
128
144
  @pid = nil
129
145
  self.end_all_nodes
146
+ self.end_all_instruments unless @android
130
147
 
131
148
  @tail.stop if @tail
132
149
  end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ # log = Flaky::Logcat.new
3
+ # log.start; log.stop
4
+ module Flaky
5
+ class Logcat
6
+ attr_reader :pid, :in, :out, :err
7
+ @@thread = nil
8
+ @@data = nil
9
+
10
+ # Start the logcat process and capture the output
11
+ def start
12
+ # make sure the adb devices command doesn't error.
13
+ while (!POSIX::Spawn::Child.new('adb kill-server; adb devices').err.empty?)
14
+ sleep 0.5
15
+ end
16
+
17
+ cmd = 'adb logcat'
18
+ @pid, @in, @@out, @err = POSIX::Spawn::popen4 cmd
19
+ @in.close
20
+ @data = ''
21
+
22
+ @@thread.exit if @@thread
23
+ @@thread = Thread.new do
24
+ # out.read blocks until the process ends
25
+ @@data = @@out.read
26
+ end
27
+ end
28
+
29
+ # Stop and return the data
30
+ def stop
31
+ begin
32
+ [@in, @out, @err].each { |io| io.close unless io.nil? || io.closed? }
33
+ Process.kill 'KILL', @pid
34
+ Process.waitpid @pid
35
+ rescue
36
+ end
37
+
38
+ @@data
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ module Flaky
3
+
4
+ # Flaky::Android.new.reset
5
+ class Android
6
+ def initialize
7
+ apk_path = ENV['APK_PATH']
8
+ raise 'Environment variable APK_PATH must be set' if apk_path.nil? ||
9
+ apk_path.empty? || File.extname(apk_path).downcase != '.apk'
10
+ @md5 = Digest::MD5.file(apk_path).hexdigest
11
+ @apk = apk_path
12
+
13
+ app_package = ENV['APP_PACKAGE']
14
+ raise 'Environment variable APP_PACKAGE must be set' if app_package.nil? ||
15
+ app_package.empty?
16
+ @package = app_package
17
+ end
18
+
19
+ def _remove_old_apks
20
+ list_apks = POSIX::Spawn::Child.new 'adb shell "ls /data/local/tmp/*.apk"'
21
+ raise "list_apks errored with: #{list_apks.err}" unless list_apks.err.empty?
22
+
23
+ apk_on_device = false
24
+ remove_apks = ''
25
+ list_apks.out.split(/\r?\n/).each do |path|
26
+ if path.include?(@md5)
27
+ apk_on_device = true
28
+ else
29
+ remove_apks += ' rm \\"' + path + '\\";'
30
+ end
31
+ end
32
+
33
+ # must return if there are no apks to remove
34
+ return if remove_apks.empty?
35
+
36
+ remove_apks = 'adb shell "' + remove_apks + '"'
37
+ remove_apks = POSIX::Spawn::Child.new remove_apks
38
+ raise "remove_apks errored with: #{remove_apks.err}" unless remove_apks.err.empty?
39
+ end
40
+
41
+ def _push_apk
42
+ # dir must exist before pushing
43
+ POSIX::Spawn::Child.new 'adb shell "mkdir /data/local/tmp/"'
44
+ push_apk = POSIX::Spawn::Child.new %Q(adb push "#{@apk}" "/data/local/tmp/#{@md5}.apk")
45
+ raise "push_apk errored with: #{push_apk.err}" unless push_apk.err.empty?
46
+ end
47
+
48
+ def _reinstall_apk
49
+ POSIX::Spawn::Child.new %Q(adb shell "am force-stop #{@package}")
50
+ apk_uninstall = POSIX::Spawn::Child.new "adb uninstall #{@package}"
51
+ raise "apk_uninstall errored with: #{apk_uninstall.err}" unless apk_uninstall.err.empty?
52
+ apk_install = POSIX::Spawn::Child.new "adb shell pm install /data/local/tmp/#{@md5}.apk"
53
+ raise "apk_install errored with: #{apk_install.err}" unless apk_install.err.empty?
54
+ end
55
+
56
+ def reset
57
+ apk_on_device = _remove_old_apks
58
+ _push_apk unless apk_on_device
59
+ _reinstall_apk
60
+ end
61
+ end
62
+ end
@@ -24,7 +24,7 @@ module Flaky
24
24
 
25
25
  count.times do
26
26
  appium.start
27
- run_cmd = "cd #{current_dir}; rake ios['#{name}']"
27
+ run_cmd = "cd #{current_dir}; rake #{os.downcase}['#{name}']"
28
28
  passed = flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium
29
29
  break if passed # move onto the next test after one successful run
30
30
  end
@@ -31,7 +31,7 @@ module Flaky
31
31
 
32
32
  count.times do
33
33
  appium.start
34
- run_cmd = "cd #{current_dir}; rake ios['#{name}']"
34
+ run_cmd = "cd #{current_dir}; rake #{os.downcase}['#{name}']"
35
35
  flaky.execute run_cmd: run_cmd, test_name: test_name, appium: appium
36
36
  end
37
37
 
data/lib/flaky/run.rb CHANGED
@@ -14,6 +14,17 @@ module Flaky
14
14
  end
15
15
  end
16
16
 
17
+ class LogArtifact
18
+ def initialize opts={}
19
+ @result_dir = opts.fetch :result_dir, ''
20
+ @pass_str = opts.fetch :pass_str, ''
21
+ end
22
+
23
+ def name str
24
+ File.join @result_dir, @pass_str, str
25
+ end
26
+ end
27
+
17
28
  class Run
18
29
  include Flaky::Color
19
30
  attr_reader :tests, :result_dir, :result_file
@@ -102,24 +113,25 @@ module Flaky
102
113
  postfix = "#{runs}_#{test_name}_" + postfix
103
114
  postfix = '0' + postfix if runs <= 9
104
115
 
105
- log_name = "#{postfix}.html"
106
- log_name = File.join result_dir, pass_str, log_name
107
- Flaky.write log_name, log
108
116
 
109
- log_name = "#{postfix}.server.log.txt"
110
- log_name = File.join result_dir, pass_str, log_name
117
+ log_file = LogArtifact.new result_dir: result_dir, pass_str: pass_str
118
+
119
+ # html Ruby test log
120
+ Flaky.write log_file.name("#{postfix}.html"), log
111
121
 
112
- File.open(log_name, 'w') do |f|
122
+ # iOS simulator system log
123
+ File.open(log_file.name("#{postfix}.server.log.txt"), 'w') do |f|
113
124
  f.write appium.tail.out.readpartial(999_999_999)
114
125
  end
115
126
 
116
- appium_log_name = File.join result_dir, pass_str, "#{postfix}.appium.html"
117
- Flaky.write appium_log_name, appium.log
127
+ # adb logcat log
128
+ logcat = appium.logcat ? appium.logcat.stop : nil
129
+ File.open(log_file.name("#{postfix}.logcat.txt"), 'w') do |f|
130
+ f.write logcat
131
+ end if logcat
118
132
 
119
- # save uncolored version
120
- # File.open(appium_log_name + '.nocolor.txt', 'w') do |f|
121
- # f.write appium.log
122
- # end
133
+ # appium server log
134
+ Flaky.write log_file.name("#{postfix}.appium.html"), appium.log
123
135
 
124
136
  passed
125
137
  end
data/lib/flaky.rb CHANGED
@@ -6,10 +6,11 @@ require 'rubygems' # gem requires
6
6
  require 'chronic_duration'
7
7
  require 'escape_utils'
8
8
  require 'posix/spawn' # http://rubygems.org/gems/posix-spawn
9
+ require 'digest/md5'
9
10
 
10
11
  module Flaky
11
- VERSION = '0.0.7' unless defined? ::Flaky::VERSION
12
- DATE = '2013-10-11' unless defined? ::Flaky::DATE
12
+ VERSION = '0.0.8' unless defined? ::Flaky::VERSION
13
+ DATE = '2013-10-17' unless defined? ::Flaky::DATE
13
14
 
14
15
  # https://github.com/appium/ruby_lib/blob/0e203d76610abd519ba9d2fe9c14b50c94df5bbd/lib/appium_lib.rb#L24
15
16
  def self.add_to_path file, path=false
data/readme.md CHANGED
@@ -4,6 +4,9 @@ Run Appium iOS tests to measure flakiness.
4
4
 
5
5
  - `gem install flaky`
6
6
  - `flake 3 ios[nop]` - Run the iOS test named nop 3 times.
7
+ - `flake 3 ios` - Run all the iOS tests up to 3 times.
8
+ If a test passes then it moves onto the next test.
9
+ If a test fails 3 times then it moves onto the next test.
7
10
 
8
11
  Results are stored in `/tmp/flaky`
9
12
 
data/release_notes.md CHANGED
@@ -1,3 +1,10 @@
1
+ #### v0.0.7 2013-10-11
2
+
3
+ - [26bc5cc](https://github.com/appium/flaky/commit/26bc5cc6b43e3de7398e6d9e8c9bb615353020eb) Release 0.0.7
4
+ - [9e854aa](https://github.com/appium/flaky/commit/9e854aae8c4b7eb64afc79c3f8716944ea9667ad) Add all tests run option
5
+ - [153119a](https://github.com/appium/flaky/commit/153119a59ba6b8c1d4c2f6d6311aa87f73b1a635) Add link to appium in the readme
6
+
7
+
1
8
  #### v0.0.6 2013-10-03
2
9
 
3
10
  - [86d8137](https://github.com/appium/flaky/commit/86d8137e3f1f348be8ee76e42bea0de36280d5a5) Release 0.0.6
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flaky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - code@bootstraponline.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-11 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic_duration
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.10.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: escape_utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.3.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.3.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: posix-spawn
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.3.6
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.3.6
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 10.1.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 10.1.0
69
69
  description: Measure flaky Ruby Appium tests.
@@ -81,6 +81,8 @@ files:
81
81
  - lib/flaky.rb
82
82
  - lib/flaky/appium.rb
83
83
  - lib/flaky/log.rb
84
+ - lib/flaky/logcat.rb
85
+ - lib/flaky/reset_android.rb
84
86
  - lib/flaky/run.rb
85
87
  - lib/flaky/run/all_tests.rb
86
88
  - lib/flaky/run/one_test.rb
@@ -100,17 +102,17 @@ require_paths:
100
102
  - lib
101
103
  required_ruby_version: !ruby/object:Gem::Requirement
102
104
  requirements:
103
- - - '>='
105
+ - - ">="
104
106
  - !ruby/object:Gem::Version
105
107
  version: 1.9.3
106
108
  required_rubygems_version: !ruby/object:Gem::Requirement
107
109
  requirements:
108
- - - '>='
110
+ - - ">="
109
111
  - !ruby/object:Gem::Version
110
112
  version: '0'
111
113
  requirements: []
112
114
  rubyforge_project:
113
- rubygems_version: 2.1.5
115
+ rubygems_version: 2.1.9
114
116
  signing_key:
115
117
  specification_version: 4
116
118
  summary: Measure flaky Ruby Appium tests