knapsack_pro 0.32.0 → 0.33.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +138 -112
- data/lib/knapsack_pro/config/env.rb +8 -0
- data/lib/knapsack_pro/formatters/rspec_queue_summary_formatter.rb +97 -0
- data/lib/knapsack_pro/runners/queue/rspec_runner.rb +9 -2
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/config/env_spec.rb +34 -0
- data/spec/knapsack_pro/runners/queue/rspec_runner_spec.rb +30 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d67c800e334256a4ec337d39b062f884dd104c66
|
4
|
+
data.tar.gz: 6abba16d16344dc3646fe33b1f72a7940790736f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f901514b6e6ee5ecc22cc72f957bf78845196b53a3aadba5dabadf2cb37b84ea5369f91deee8eb220238c24a7736540067ef4deb9f4c2899020141abba1868bd
|
7
|
+
data.tar.gz: a2f8feb04f69e5fcb5f3a702a239a45238ffdf92c15a2c66ffb6e5618c2f64527722a5bb5037e72d396defec1e4ceb45eebab4aa6f153cf22139c3bfcc270c2a
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
* TODO
|
4
4
|
|
5
|
+
### 0.33.0
|
6
|
+
|
7
|
+
* Add RSpec Queue Formatter to hide duplicated pending and failed tests in Queue Mode
|
8
|
+
|
9
|
+
You can keep duplicated pending/failed summary with flag `KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS`. More can be found in read me.
|
10
|
+
|
11
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/31
|
12
|
+
|
13
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.32.0...v0.33.0
|
14
|
+
|
5
15
|
### 0.32.0
|
6
16
|
|
7
17
|
* Add encryption for branch names
|
data/README.md
CHANGED
@@ -74,6 +74,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get most optimal test sui
|
|
74
74
|
- [Additional info about queue mode](#additional-info-about-queue-mode)
|
75
75
|
- [Extra configuration for Queue Mode](#extra-configuration-for-queue-mode)
|
76
76
|
- [KNAPSACK_PRO_FIXED_QUEUE_SPLIT (remember queue split on retry CI node)](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node)
|
77
|
+
- [KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS (hide duplicated summary of pending and failed tests)](#knapsack_pro_modify_default_rspec_formatters-hide-duplicated-summary-of-pending-and-failed-tests)
|
77
78
|
- [Supported test runners in queue mode](#supported-test-runners-in-queue-mode)
|
78
79
|
- [Extra configuration for CI server](#extra-configuration-for-ci-server)
|
79
80
|
- [Info about ENV variables](#info-about-env-variables)
|
@@ -98,33 +99,36 @@ The knapsack_pro has also [queue mode](#queue-mode) to get most optimal test sui
|
|
98
99
|
- [Info for snap-ci.com users](#info-for-snap-cicom-users)
|
99
100
|
- [Info for Jenkins users](#info-for-jenkins-users)
|
100
101
|
- [FAQ](#faq)
|
101
|
-
- [
|
102
|
-
- [
|
103
|
-
- [
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
- [
|
111
|
-
|
102
|
+
- [Common problems](#common-problems)
|
103
|
+
- [Why I see API error commit_hash parameter is required?](#why-i-see-api-error-commit_hash-parameter-is-required)
|
104
|
+
- [Queue Mode problems](#queue-mode-problems)
|
105
|
+
- [Why when I use Queue Mode for RSpec and test fails then I see multiple times info about failed test in RSpec result?](#why-when-i-use-queue-mode-for-rspec-and-test-fails-then-i-see-multiple-times-info-about-failed-test-in-rspec-result)
|
106
|
+
- [Why when I use Queue Mode for RSpec then I see multiple times the same pending tests?](#why-when-i-use-queue-mode-for-rspec-then-i-see-multiple-times-the-same-pending-tests)
|
107
|
+
- [Does in Queue Mode the RSpec is initialized many times that causes Rails load over and over again?](#does-in-queue-mode-the-rspec-is-initialized-many-times-that-causes-rails-load-over-and-over-again)
|
108
|
+
- [Why my tests are executed twice in queue mode? Why CI node runs whole test suite again?](#why-my-tests-are-executed-twice-in-queue-mode-why-ci-node-runs-whole-test-suite-again)
|
109
|
+
- [How to fix capybara-screenshot fail with `SystemStackError: stack level too deep` when using Queue Mode for RSpec?](#how-to-fix-capybara-screenshot-fail-with-systemstackerror-stack-level-too-deep-when-using-queue-mode-for-rspec)
|
110
|
+
- [General questions](#general-questions)
|
111
|
+
- [How to run tests for particular CI node in your development environment](#how-to-run-tests-for-particular-ci-node-in-your-development-environment)
|
112
|
+
- [for knapack_pro regular mode](#for-knapack_pro-regular-mode)
|
113
|
+
- [for knapsack_pro queue mode](#for-knapsack_pro-queue-mode)
|
114
|
+
- [What happens when Knapsack Pro API is not available/not reachable temporarily?](#what-happens-when-knapsack-pro-api-is-not-availablenot-reachable-temporarily)
|
115
|
+
- [for knapack_pro regular mode](#for-knapack_pro-regular-mode-1)
|
116
|
+
- [for knapsack_pro queue mode](#for-knapsack_pro-queue-mode-1)
|
117
|
+
- [How can I change log level?](#how-can-i-change-log-level)
|
118
|
+
- [How to split tests based on test level instead of test file level?](#how-to-split-tests-based-on-test-level-instead-of-test-file-level)
|
119
|
+
- [A. Create multiple small test files](#a-create-multiple-small-test-files)
|
120
|
+
- [B. Use tags to mark set of tests in particular test file](#b-use-tags-to-mark-set-of-tests-in-particular-test-file)
|
121
|
+
- [How to make knapsack_pro works for forked repositories of my project?](#how-to-make-knapsack_pro-works-for-forked-repositories-of-my-project)
|
122
|
+
- [How to use junit formatter?](#how-to-use-junit-formatter)
|
123
|
+
- [How many API keys I need?](#how-many-api-keys-i-need)
|
124
|
+
- [What is optimal order of test commands?](#what-is-optimal-order-of-test-commands)
|
125
|
+
- [How to set `before(:suite)` and `after(:suite)` RSpec hooks in Queue Mode (Percy.io example)?](#how-to-set-beforesuite-and-aftersuite-rspec-hooks-in-queue-mode-percyio-example)
|
126
|
+
- [How to call `before(:suite)` and `after(:suite)` RSpec hooks only once in Queue Mode?](#how-to-call-beforesuite-and-aftersuite-rspec-hooks-only-once-in-queue-mode)
|
127
|
+
- [How to run knapsack_pro with parallel_tests gem?](#how-to-run-knapsack_pro-with-parallel_tests-gem)
|
112
128
|
- [Questions around data usage and security](#questions-around-data-usage-and-security)
|
113
129
|
- [What data is sent to your servers?](#what-data-is-sent-to-your-servers)
|
114
130
|
- [How is that data secured?](#how-is-that-data-secured)
|
115
131
|
- [Who has access to the data?](#who-has-access-to-the-data)
|
116
|
-
- [Why when I use Queue Mode for RSpec and test fails then I see multiple times info about failed test in RSpec result?](#why-when-i-use-queue-mode-for-rspec-and-test-fails-then-i-see-multiple-times-info-about-failed-test-in-rspec-result)
|
117
|
-
- [Why when I use Queue Mode for RSpec then I see multiple times the same pending tests?](#why-when-i-use-queue-mode-for-rspec-then-i-see-multiple-times-the-same-pending-tests)
|
118
|
-
- [Does in Queue Mode the RSpec is initialized many times that causes Rails load over and over again?](#does-in-queue-mode-the-rspec-is-initialized-many-times-that-causes-rails-load-over-and-over-again)
|
119
|
-
- [How to use junit formatter?](#how-to-use-junit-formatter)
|
120
|
-
- [Why I see API error commit_hash parameter is required?](#why-i-see-api-error-commit_hash-parameter-is-required)
|
121
|
-
- [How many API keys I need?](#how-many-api-keys-i-need)
|
122
|
-
- [What is optimal order of test commands?](#what-is-optimal-order-of-test-commands)
|
123
|
-
- [Why my tests are executed twice in queue mode? Why CI node runs whole test suite again?](#why-my-tests-are-executed-twice-in-queue-mode-why-ci-node-runs-whole-test-suite-again)
|
124
|
-
- [How to set `before(:suite)` and `after(:suite)` RSpec hooks in Queue Mode (Percy.io example)?](#how-to-set-beforesuite-and-aftersuite-rspec-hooks-in-queue-mode-percyio-example)
|
125
|
-
- [How to call `before(:suite)` and `after(:suite)` RSpec hooks only once in Queue Mode?](#how-to-call-beforesuite-and-aftersuite-rspec-hooks-only-once-in-queue-mode)
|
126
|
-
- [How to fix capybara-screenshot fail with `SystemStackError: stack level too deep` when using Queue Mode for RSpec?](#how-to-fix-capybara-screenshot-fail-with-systemstackerror-stack-level-too-deep-when-using-queue-mode-for-rspec)
|
127
|
-
- [How to run knapsack_pro with parallel_tests gem?](#how-to-run-knapsack_pro-with-parallel_tests-gem)
|
128
132
|
- [Gem tests](#gem-tests)
|
129
133
|
- [Spec](#spec)
|
130
134
|
- [Contributing](#contributing)
|
@@ -392,7 +396,7 @@ There might be some cached test suite splits for git commits you run in past for
|
|
392
396
|
|
393
397
|
* `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=false` (default)
|
394
398
|
|
395
|
-
By default, the fixed queue split is off. It means when you will run tests for the same commit hash and a total number of nodes and for the same branch
|
399
|
+
By default, the fixed queue split is off. It means when you will run tests for the same commit hash and a total number of nodes and for the same branch, and the CI build ID is different with second tests run then the queue will be generated dynamically and CI nodes will fetch from Knapsack Pro API the test files in a dynamic way. This is default because it gives the most optimal test suite split for the whole test build across all CI nodes.
|
396
400
|
|
397
401
|
* `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`
|
398
402
|
|
@@ -411,6 +415,18 @@ There might be some cached test suite splits for git commits you run in past for
|
|
411
415
|
|
412
416
|
To [reproduce tests executed on CI node](#for-knapsack_pro-queue-mode) in development environment please see FAQ.
|
413
417
|
|
418
|
+
#### KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS (hide duplicated summary of pending and failed tests)
|
419
|
+
|
420
|
+
* `KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=true` (default)
|
421
|
+
|
422
|
+
By default, the knapack_pro will monkey patch [RSpec Formatters](https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/command-line/format-option) in order to
|
423
|
+
hide the summary of pending and failed tests after each intermediate run of tests fetched from the work queue on Knapsack Pro API.
|
424
|
+
knapack_pro shows summary of all pending and failed tests at the very end when work queue ended. If you use your custom formatter and you have problem with it then you can disable `KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=false` monkey patching.
|
425
|
+
|
426
|
+
* `KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=false`
|
427
|
+
|
428
|
+
It causes to show summary of pending and failed tests after each intermediate tests run from the work queue. The summary will grown cumulatively after each intermediate tests run so it means you will see multiple times summary of the same pending/failed tests. It doesn't mean the test files are executed twice. Test files are executed only once. Only summary report grows cumulatively.
|
429
|
+
|
414
430
|
### Supported test runners in queue mode
|
415
431
|
|
416
432
|
At this moment the queue mode works for:
|
@@ -791,9 +807,66 @@ If you are going to relay on rspec to autobalance build when cucumber tests were
|
|
791
807
|
|
792
808
|
## FAQ
|
793
809
|
|
794
|
-
###
|
810
|
+
### Common problems
|
811
|
+
|
812
|
+
#### Why I see API error commit_hash parameter is required?
|
813
|
+
|
814
|
+
ERROR -- : [knapsack_pro] {"errors"=>[{"commit_hash"=>["parameter is required"]}]}
|
815
|
+
|
816
|
+
When Knapsack Pro API returns error like above the problem is because you use CI provider not supported by knapack_pro which means
|
817
|
+
knapack_pro gem cannot determine the git commit hash and branch name. To fix this problem you can do:
|
818
|
+
|
819
|
+
* if you have git installed on CI node then you can use it to determine git commit hash and branch name. [See this](#when-you-set-global-variable-knapsack_pro_repository_adaptergit-required-when-ci-provider-is-not-supported)
|
820
|
+
* if you have no git installed on CI node then you should manually set `KNAPSACK_PRO_BRANCH` and `KNAPSACK_PRO_COMMIT_HASH`. For instance this might be useful when you use Jenkins. [See this](#when-you-not-set-global-variable-knapsack_pro_repository_adapter-default)
|
821
|
+
|
822
|
+
#### Queue Mode problems
|
823
|
+
|
824
|
+
##### Why when I use Queue Mode for RSpec and test fails then I see multiple times info about failed test in RSpec result?
|
825
|
+
|
826
|
+
The problem may happen when you use old knapsack_pro `< 0.33.0` or if you use custom rspec formatter, or when you set flag [KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=false](#knapsack_pro_modify_default_rspec_formatters-hide-duplicated-summary-of-pending-and-failed-tests).
|
827
|
+
|
828
|
+
When you use Queue Mode then knapack_pro does multiple requests to Knapsack Pro API and fetches a few test files to execute.
|
829
|
+
This means RSpec will remember failed tests so far and it will present them at the end of each executed test subset if flag `KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=false`.
|
830
|
+
You can see the list of all failed test files at the end of knapack_pro queue mode command.
|
831
|
+
|
832
|
+
##### Why when I use Queue Mode for RSpec then I see multiple times the same pending tests?
|
833
|
+
|
834
|
+
The problem may happen when you use old knapsack_pro `< 0.33.0` or if you use custom rspec formatter, or when you set flag [KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=false](#knapsack_pro_modify_default_rspec_formatters-hide-duplicated-summary-of-pending-and-failed-tests).
|
835
|
+
|
836
|
+
When you use Queue Mode then knapack_pro does multiple requests to Knapsack Pro API and fetches a few test files to execute.
|
837
|
+
This means RSpec will remember pending tests so far and it will present them at the end of each executed test subset if flag `KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS=false`.
|
838
|
+
You can see the list of all pending test files at the end of knapack_pro queue mode command.
|
839
|
+
|
840
|
+
##### Does in Queue Mode the RSpec is initialized many times that causes Rails load over and over again?
|
841
|
+
|
842
|
+
No. In Queue Mode the RSpec configuration is updated every time when knapsack_pro gem gets a new set of test files from the Knapsack Pro API and it looks in knapsack_pro output like RSpec was loaded many times but in fact, it loads your project environment only once.
|
843
|
+
|
844
|
+
##### Why my tests are executed twice in queue mode? Why CI node runs whole test suite again?
|
845
|
+
|
846
|
+
This may happen when you use not supported CI provider by knapack_pro. It's because of missing value of CI build ID. You can set unique `KNAPSACK_PRO_CI_NODE_BUILD_ID` for each CI build. The problem with test suite run again happens when one of your CI node started work later when all other CI nodes already executed whole test suite.
|
847
|
+
The slow CI node that started work late will initialize a new queue hence the tests executed twice.
|
848
|
+
|
849
|
+
To solve this problem you can set `KNAPSACK_PRO_CI_NODE_BUILD_ID` as mentioned above or you can set `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`.
|
850
|
+
Please [read this](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node).
|
795
851
|
|
796
|
-
|
852
|
+
##### How to fix capybara-screenshot fail with `SystemStackError: stack level too deep` when using Queue Mode for RSpec?
|
853
|
+
|
854
|
+
Please use fixed version of capybara-screenshot.
|
855
|
+
|
856
|
+
```
|
857
|
+
# Gemfile
|
858
|
+
group :test do
|
859
|
+
gem 'capybara-screenshot', github: 'ArturT/capybara-screenshot', branch: 'fix-reporter_module-loaded-twice'
|
860
|
+
end
|
861
|
+
```
|
862
|
+
|
863
|
+
Here is [fix PR](https://github.com/mattheworiordan/capybara-screenshot/pull/205) to official capybara-screenshot repository and the explanation of the problem.
|
864
|
+
|
865
|
+
### General questions
|
866
|
+
|
867
|
+
#### How to run tests for particular CI node in your development environment
|
868
|
+
|
869
|
+
##### for knapack_pro regular mode
|
797
870
|
|
798
871
|
In your development environment you can debug tests that were run on the particular CI node.
|
799
872
|
For instance to run subset of tests for the first CI node with specified seed you can do.
|
@@ -821,7 +894,7 @@ Command similar to above can be executed in your development this way:
|
|
821
894
|
|
822
895
|
If you were running your tests with `--order random` on your CI then you can additionaly pass seed param with proper value in above command (`--seed 123`).
|
823
896
|
|
824
|
-
|
897
|
+
##### for knapsack_pro queue mode
|
825
898
|
|
826
899
|
There are a few ways to reproduce tests executed on CI node in your development environment.
|
827
900
|
|
@@ -864,17 +937,17 @@ There are a few ways to reproduce tests executed on CI node in your development
|
|
864
937
|
KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true \
|
865
938
|
bundle exec rake "knapsack_pro:queue:rspec[--seed 123]"
|
866
939
|
|
867
|
-
|
940
|
+
#### What happens when Knapsack Pro API is not available/not reachable temporarily?
|
868
941
|
|
869
|
-
|
942
|
+
##### for knapack_pro regular mode
|
870
943
|
|
871
944
|
knapack_pro gem will retry requests to Knapsack Pro API multiple times every few seconds til it switch to fallback behaviour and it will split test files across CI nodes based on popular test directory names.
|
872
945
|
|
873
|
-
|
946
|
+
##### for knapsack_pro queue mode
|
874
947
|
|
875
948
|
knapack_pro gem will retry requests to Knapsack Pro API multiple times every few seconds til it fails.
|
876
949
|
|
877
|
-
|
950
|
+
#### How can I change log level?
|
878
951
|
|
879
952
|
You can change log level by specifying the `KNAPSACK_PRO_LOG_LEVEL` environment variable.
|
880
953
|
|
@@ -887,16 +960,16 @@ Recommended log levels you can use:
|
|
887
960
|
* `debug` is default log level and it is recommended to log details about requests to Knapsack Pro API. Thanks to that you can debug things or ensure everything works. For instance in [user dashboard](https://knapsackpro.com/dashboard) you can find tips referring to debug logs.
|
888
961
|
* `info` level shows message like how to retry tests in development or info why something works this way or the other (for instance why tests were not executed on the CI node). You can use `info` level when you really don't want to see all debug messages from default log level.
|
889
962
|
|
890
|
-
|
963
|
+
#### How to split tests based on test level instead of test file level?
|
891
964
|
|
892
965
|
If you want to split one big test file (test file with long time execution) across multiple CI nodes then you can:
|
893
966
|
|
894
|
-
|
967
|
+
##### A. Create multiple small test files
|
895
968
|
|
896
969
|
Create multiple small test files instead of one long running test file with many test cases.
|
897
970
|
A lot of small test files will give you better test suite split results.
|
898
971
|
|
899
|
-
|
972
|
+
##### B. Use tags to mark set of tests in particular test file
|
900
973
|
|
901
974
|
Another way is to use tags to mark subset of tests in particular test file and then split tests based on tags.
|
902
975
|
|
@@ -933,7 +1006,7 @@ You need to run below commands for each CI node.
|
|
933
1006
|
# run other tests without tag A & B
|
934
1007
|
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=api_key_for_tests_without_tags_A_and_B bundle exec rake "knapsack_pro:rspec[--tag ~tagA --tag ~tagB]"
|
935
1008
|
|
936
|
-
|
1009
|
+
#### How to make knapsack_pro works for forked repositories of my project?
|
937
1010
|
|
938
1011
|
Imagine one of the scenarios, for this example I use the Travis-CI.
|
939
1012
|
|
@@ -961,49 +1034,7 @@ fi
|
|
961
1034
|
Now you can use `bin/knapsack_pro_rspec` command instead of `bundle exec rake knapsack_pro:rspec`.
|
962
1035
|
Remember to follow other steps required for your CI provider.
|
963
1036
|
|
964
|
-
|
965
|
-
|
966
|
-
#### What data is sent to your servers?
|
967
|
-
|
968
|
-
The knapsack_pro gem sends branch name, commit hash, CI total node number, CI index node number, the test file paths like `spec/models/user_spec.rb` and the time execution of each test file path as a float.
|
969
|
-
|
970
|
-
Here is the [full specification of the API](http://docs.knapsackpro.com/api/v1/) used by knapsack_pro gem.
|
971
|
-
|
972
|
-
#### How is that data secured?
|
973
|
-
|
974
|
-
The test file paths can be [encrypted](#test-file-names-encryption) on your CI node with your salt and later send to knapsackpro.com API.
|
975
|
-
You generate salt locally and only you can decrypt the test file paths.
|
976
|
-
|
977
|
-
Connection with knapsackpro.com server is via https.
|
978
|
-
|
979
|
-
Regarding payments we use the BraintreePayments.com and they store credit cards and your private information.
|
980
|
-
|
981
|
-
#### Who has access to the data?
|
982
|
-
|
983
|
-
I’m the only admin so I can preview data in case you need help with debugging some problem etc. I’m not able to decrypt them without knowing the salt.
|
984
|
-
|
985
|
-
When you sign in to your user dashboard then you can preview data for recent 100 builds on CI. If the test file paths are encrypted then you only see hashes for test file paths.
|
986
|
-
You need to [decrypt](#how-to-debug-test-file-names) them locally on your machine to find out what each test file hash is.
|
987
|
-
|
988
|
-
### Why when I use Queue Mode for RSpec and test fails then I see multiple times info about failed test in RSpec result?
|
989
|
-
|
990
|
-
RSpec collects information about failed tests and presents it at the end of RSpec result.
|
991
|
-
When you use Queue Mode then knapack_pro does multiple requests to Knapsack Pro API and fetches a few test files to execute.
|
992
|
-
This means RSpec will remember failed tests so far and it will present them at the end of each executed test subset.
|
993
|
-
You can see the list of all failed test files at the end of knapack_pro queue mode command.
|
994
|
-
|
995
|
-
### Why when I use Queue Mode for RSpec then I see multiple times the same pending tests?
|
996
|
-
|
997
|
-
RSpec collects information about pending tests and presents it at the end of RSpec result.
|
998
|
-
When you use Queue Mode then knapack_pro does multiple requests to Knapsack Pro API and fetches a few test files to execute.
|
999
|
-
This means RSpec will remember pending tests so far and it will present them at the end of each executed test subset.
|
1000
|
-
You can see the list of all pending test files at the end of knapack_pro queue mode command.
|
1001
|
-
|
1002
|
-
### Does in Queue Mode the RSpec is initialized many times that causes Rails load over and over again?
|
1003
|
-
|
1004
|
-
No. In Queue Mode the RSpec configuration is updated every time when knapsack_pro gem gets a new set of test files from the Knapsack Pro API and it looks in knapsack_pro output like RSpec was loaded many times but in fact, it loads your project environment only once.
|
1005
|
-
|
1006
|
-
### How to use junit formatter?
|
1037
|
+
#### How to use junit formatter?
|
1007
1038
|
|
1008
1039
|
You can use junit formatter for rspec thanks to gem [rspec_junit_formatter](https://github.com/sj26/rspec_junit_formatter).
|
1009
1040
|
Here you can find example how to generate `rspec.xml` file with junit format and at the same time show normal documentation format output for RSpec.
|
@@ -1015,17 +1046,7 @@ Here you can find example how to generate `rspec.xml` file with junit format and
|
|
1015
1046
|
# The xml report will contain all tests executed across intermediate test subset runs based on queue
|
1016
1047
|
bundle exec rake "knapsack_pro:queue:rspec[--format documentation --format RspecJunitFormatter --out tmp/rspec.xml]"
|
1017
1048
|
|
1018
|
-
|
1019
|
-
|
1020
|
-
ERROR -- : [knapsack_pro] {"errors"=>[{"commit_hash"=>["parameter is required"]}]}
|
1021
|
-
|
1022
|
-
When Knapsack Pro API returns error like above the problem is because you use CI provider not supported by knapack_pro which means
|
1023
|
-
knapack_pro gem cannot determine the git commit hash and branch name. To fix this problem you can do:
|
1024
|
-
|
1025
|
-
* if you have git installed on CI node then you can use it to determine git commit hash and branch name. [See this](#when-you-set-global-variable-knapsack_pro_repository_adaptergit-required-when-ci-provider-is-not-supported)
|
1026
|
-
* if you have no git installed on CI node then you should manually set `KNAPSACK_PRO_BRANCH` and `KNAPSACK_PRO_COMMIT_HASH`. For instance this might be useful when you use Jenkins. [See this](#when-you-not-set-global-variable-knapsack_pro_repository_adapter-default)
|
1027
|
-
|
1028
|
-
### How many API keys I need?
|
1049
|
+
#### How many API keys I need?
|
1029
1050
|
|
1030
1051
|
Basically you need as many API keys as you have steps in your build.
|
1031
1052
|
|
@@ -1044,7 +1065,7 @@ Note:
|
|
1044
1065
|
* If you pass `--tag tagA` or `--tag ~tagA` then you run subset of your whole test suite hence you need separate API key.
|
1045
1066
|
* If you use regular or queue mode then you need separate API key for each mode.
|
1046
1067
|
|
1047
|
-
|
1068
|
+
#### What is optimal order of test commands?
|
1048
1069
|
|
1049
1070
|
__Tip 1:__
|
1050
1071
|
|
@@ -1068,13 +1089,7 @@ When you have short test suite, for instance in javascript then you could distri
|
|
1068
1089
|
|
1069
1090
|
You will run your javascript tests on single CI node and the knapack_pro will auto-balance CI build with Queue Mode. Thanks to that CI build time execution will be flat and optimal (as fast as possible).
|
1070
1091
|
|
1071
|
-
|
1072
|
-
|
1073
|
-
This may happen when one of your CI node started work later when all other CI nodes already executed whole test suite.
|
1074
|
-
The slow CI node will initialize a new queue hence the tests executed twice. To solve this problem you should set `KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true`.
|
1075
|
-
Please [read this](#knapsack_pro_fixed_queue_split-remember-queue-split-on-retry-ci-node).
|
1076
|
-
|
1077
|
-
### How to set `before(:suite)` and `after(:suite)` RSpec hooks in Queue Mode (Percy.io example)?
|
1092
|
+
#### How to set `before(:suite)` and `after(:suite)` RSpec hooks in Queue Mode (Percy.io example)?
|
1078
1093
|
|
1079
1094
|
Some tools like [Percy.io](https://percy.io/docs/clients/ruby/capybara-rails) requires to set hooks for RSpec `before(:suite)` and `after(:suite)`.
|
1080
1095
|
Knapsack Pro Queue Mode runs subset of test files from the work queue many times. This means the RSpec hooks `before(:suite)` and `after(:suite)` will execute multiple times. If you want to run some code only once before Queue Mode starts work and after it finishes then you should do it this way:
|
@@ -1089,7 +1104,7 @@ Percy::Capybara.initialize_build
|
|
1089
1104
|
at_exit { Percy::Capybara.finalize_build }
|
1090
1105
|
```
|
1091
1106
|
|
1092
|
-
|
1107
|
+
#### How to call `before(:suite)` and `after(:suite)` RSpec hooks only once in Queue Mode?
|
1093
1108
|
|
1094
1109
|
Knapsack Pro Queue Mode runs subset of test files from the work queue many times. This means the RSpec hooks `before(:suite)` and `after(:suite)` will be executed multiple times. If you want to run some code only once before Queue Mode starts work and after it finishes then you should do it this way:
|
1095
1110
|
|
@@ -1111,20 +1126,7 @@ RSpec.configure do |config|
|
|
1111
1126
|
end
|
1112
1127
|
```
|
1113
1128
|
|
1114
|
-
|
1115
|
-
|
1116
|
-
Please use fixed version of capybara-screenshot.
|
1117
|
-
|
1118
|
-
```
|
1119
|
-
# Gemfile
|
1120
|
-
group :test do
|
1121
|
-
gem 'capybara-screenshot', github: 'ArturT/capybara-screenshot', branch: 'fix-reporter_module-loaded-twice'
|
1122
|
-
end
|
1123
|
-
```
|
1124
|
-
|
1125
|
-
Here is [fix PR](https://github.com/mattheworiordan/capybara-screenshot/pull/205) to official capybara-screenshot repository and the explanation of the problem.
|
1126
|
-
|
1127
|
-
### How to run knapsack_pro with parallel_tests gem?
|
1129
|
+
#### How to run knapsack_pro with parallel_tests gem?
|
1128
1130
|
|
1129
1131
|
You can run knapsack_pro with [parallel_tests](https://github.com/grosser/parallel_tests) gem to run multiple concurrent knapsack_pro commands per CI node.
|
1130
1132
|
|
@@ -1207,6 +1209,30 @@ To ensure everything works you can check output for each CI node.
|
|
1207
1209
|
(tests output here)
|
1208
1210
|
```
|
1209
1211
|
|
1212
|
+
### Questions around data usage and security
|
1213
|
+
|
1214
|
+
#### What data is sent to your servers?
|
1215
|
+
|
1216
|
+
The knapsack_pro gem sends branch name, commit hash, CI total node number, CI index node number, the test file paths like `spec/models/user_spec.rb` and the time execution of each test file path as a float.
|
1217
|
+
|
1218
|
+
Here is the [full specification of the API](http://docs.knapsackpro.com/api/v1/) used by knapsack_pro gem.
|
1219
|
+
|
1220
|
+
#### How is that data secured?
|
1221
|
+
|
1222
|
+
The test file paths and/or branch names can be [encrypted](#test-file-names-encryption) on your CI node with a salt and later send to knapsackpro.com API.
|
1223
|
+
You generate the salt locally and only you can decrypt the test file paths or branch names.
|
1224
|
+
|
1225
|
+
Connection with knapsackpro.com server is via https.
|
1226
|
+
|
1227
|
+
Regarding payments we use the BraintreePayments.com and they store credit cards and your private information.
|
1228
|
+
|
1229
|
+
#### Who has access to the data?
|
1230
|
+
|
1231
|
+
I’m the only admin so I can preview data in case you need help with debugging some problem etc. I’m not able to decrypt them without knowing the salt.
|
1232
|
+
|
1233
|
+
When you sign in to your user dashboard then you can preview data for recent 100 builds on CI. If the test file paths are encrypted then you only see hashes for test file paths.
|
1234
|
+
You need to [decrypt](#how-to-debug-test-file-names) them locally on your machine to find out what each test file hash is.
|
1235
|
+
|
1210
1236
|
## Gem tests
|
1211
1237
|
|
1212
1238
|
### Spec
|
@@ -75,6 +75,14 @@ module KnapsackPro
|
|
75
75
|
test_files_encrypted == 'true'
|
76
76
|
end
|
77
77
|
|
78
|
+
def modify_default_rspec_formatters
|
79
|
+
ENV.fetch('KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS', true)
|
80
|
+
end
|
81
|
+
|
82
|
+
def modify_default_rspec_formatters?
|
83
|
+
modify_default_rspec_formatters.to_s == 'true'
|
84
|
+
end
|
85
|
+
|
78
86
|
def branch_encrypted
|
79
87
|
ENV['KNAPSACK_PRO_BRANCH_ENCRYPTED']
|
80
88
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
RSpec::Support.require_rspec_core('formatters/base_formatter')
|
2
|
+
RSpec::Support.require_rspec_core('formatters/base_text_formatter')
|
3
|
+
|
4
|
+
module KnapsackPro
|
5
|
+
module Formatters
|
6
|
+
module RSpecHideFailuresAndPendingExtension
|
7
|
+
def dump_failures(notification); end
|
8
|
+
def dump_pending(notification); end
|
9
|
+
def dump_summary(summary); end
|
10
|
+
end
|
11
|
+
|
12
|
+
class RSpecQueueSummaryFormatter < RSpec::Core::Formatters::BaseFormatter
|
13
|
+
RSpec::Core::Formatters.register self, :dump_failures, :dump_pending
|
14
|
+
|
15
|
+
def self.registered_output=(output)
|
16
|
+
@registered_output = {
|
17
|
+
ENV['KNAPSACK_PRO_QUEUE_ID'] => output
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.registered_output
|
22
|
+
@registered_output[ENV['KNAPSACK_PRO_QUEUE_ID']]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.most_recent_failures_summary=(fully_formatted_failed_examples)
|
26
|
+
@most_recent_failures_summary = {
|
27
|
+
ENV['KNAPSACK_PRO_QUEUE_ID'] => fully_formatted_failed_examples
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.most_recent_failures_summary
|
32
|
+
@most_recent_failures_summary ||= {}
|
33
|
+
@most_recent_failures_summary[ENV['KNAPSACK_PRO_QUEUE_ID']] || []
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.most_recent_pending=(fully_formatted_pending_examples)
|
37
|
+
@most_recent_pending = {
|
38
|
+
ENV['KNAPSACK_PRO_QUEUE_ID'] => fully_formatted_pending_examples
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.most_recent_pending
|
43
|
+
@most_recent_pending ||= {}
|
44
|
+
@most_recent_pending[ENV['KNAPSACK_PRO_QUEUE_ID']] || []
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.most_recent_summary=(fully_formatted)
|
48
|
+
@most_recent_summary = {
|
49
|
+
ENV['KNAPSACK_PRO_QUEUE_ID'] => fully_formatted
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.most_recent_summary
|
54
|
+
@most_recent_summary ||= {}
|
55
|
+
@most_recent_summary[ENV['KNAPSACK_PRO_QUEUE_ID']] || []
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.print_summary
|
59
|
+
registered_output.puts('Knapsack Pro Queue finished!')
|
60
|
+
registered_output.puts('')
|
61
|
+
|
62
|
+
unless most_recent_pending.empty?
|
63
|
+
registered_output.puts('All pending tests on this CI node:')
|
64
|
+
registered_output.puts(most_recent_pending)
|
65
|
+
end
|
66
|
+
|
67
|
+
unless most_recent_failures_summary.empty?
|
68
|
+
registered_output.puts('All failed tests on this CI node:')
|
69
|
+
registered_output.puts(most_recent_failures_summary)
|
70
|
+
end
|
71
|
+
|
72
|
+
registered_output.puts(most_recent_summary)
|
73
|
+
end
|
74
|
+
|
75
|
+
def initialize(output)
|
76
|
+
super
|
77
|
+
self.class.registered_output = output
|
78
|
+
end
|
79
|
+
|
80
|
+
def dump_failures(notification)
|
81
|
+
return if notification.failure_notifications.empty?
|
82
|
+
self.class.most_recent_failures_summary = notification.fully_formatted_failed_examples
|
83
|
+
end
|
84
|
+
|
85
|
+
def dump_pending(notification)
|
86
|
+
return if notification.pending_examples.empty?
|
87
|
+
self.class.most_recent_pending = notification.fully_formatted_pending_examples
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
if KnapsackPro::Config::Env.modify_default_rspec_formatters?
|
94
|
+
class RSpec::Core::Formatters::BaseTextFormatter
|
95
|
+
prepend KnapsackPro::Formatters::RSpecHideFailuresAndPendingExtension
|
96
|
+
end
|
97
|
+
end
|
@@ -4,6 +4,7 @@ module KnapsackPro
|
|
4
4
|
class RSpecRunner < BaseRunner
|
5
5
|
def self.run(args)
|
6
6
|
require 'rspec/core'
|
7
|
+
require_relative '../../formatters/rspec_queue_summary_formatter'
|
7
8
|
|
8
9
|
ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN'] = KnapsackPro::Config::Env.test_suite_token_rspec
|
9
10
|
ENV['KNAPSACK_PRO_QUEUE_RECORDING_ENABLED'] = 'true'
|
@@ -11,7 +12,12 @@ module KnapsackPro
|
|
11
12
|
|
12
13
|
runner = new(KnapsackPro::Adapters::RSpecAdapter)
|
13
14
|
|
14
|
-
cli_args = (args || '').split
|
15
|
+
cli_args = (args || '').split
|
16
|
+
# if user didn't provide the format then use explicitly default progress formatter
|
17
|
+
# in order to avoid KnapsackPro::Formatters::RSpecQueueSummaryFormatter being the only default formatter
|
18
|
+
cli_args += ['--format', 'progress'] unless cli_args.include?('--format')
|
19
|
+
cli_args += [
|
20
|
+
'--format', KnapsackPro::Formatters::RSpecQueueSummaryFormatter.to_s,
|
15
21
|
'--default-path', runner.test_dir,
|
16
22
|
]
|
17
23
|
run_tests(runner, true, cli_args, 0, [])
|
@@ -22,8 +28,9 @@ module KnapsackPro
|
|
22
28
|
|
23
29
|
if test_file_paths.empty?
|
24
30
|
unless all_test_file_paths.empty?
|
25
|
-
|
31
|
+
KnapsackPro::Formatters::RSpecQueueSummaryFormatter.print_summary
|
26
32
|
|
33
|
+
cli_args = args + all_test_file_paths
|
27
34
|
log_rspec_command(cli_args, :end_of_queue)
|
28
35
|
end
|
29
36
|
|
data/lib/knapsack_pro/version.rb
CHANGED
@@ -302,6 +302,40 @@ describe KnapsackPro::Config::Env do
|
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
|
+
describe '.modify_default_rspec_formatters' do
|
306
|
+
subject { described_class.modify_default_rspec_formatters }
|
307
|
+
|
308
|
+
context 'when ENV exists' do
|
309
|
+
let(:modify_default_rspec_formatters) { 'false' }
|
310
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS' => modify_default_rspec_formatters }) }
|
311
|
+
it { should eq modify_default_rspec_formatters }
|
312
|
+
end
|
313
|
+
|
314
|
+
context "when ENV doesn't exist" do
|
315
|
+
it { should be true }
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
describe '.modify_default_rspec_formatters?' do
|
320
|
+
subject { described_class.modify_default_rspec_formatters? }
|
321
|
+
|
322
|
+
before do
|
323
|
+
expect(described_class).to receive(:modify_default_rspec_formatters).and_return(modify_default_rspec_formatters)
|
324
|
+
end
|
325
|
+
|
326
|
+
context 'when enabled' do
|
327
|
+
let(:modify_default_rspec_formatters) { true }
|
328
|
+
|
329
|
+
it { should be true }
|
330
|
+
end
|
331
|
+
|
332
|
+
context 'when disabled' do
|
333
|
+
let(:modify_default_rspec_formatters) { false }
|
334
|
+
|
335
|
+
it { should be false }
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
305
339
|
describe '.branch_encrypted' do
|
306
340
|
subject { described_class.branch_encrypted }
|
307
341
|
|
@@ -1,4 +1,13 @@
|
|
1
|
+
|
1
2
|
describe KnapsackPro::Runners::Queue::RSpecRunner do
|
3
|
+
before do
|
4
|
+
# we don't want to modify rspec formatters because we want to see tests summary at the end
|
5
|
+
# when you run this test file or whole test suite for the knapsack_pro gem
|
6
|
+
stub_const('ENV', { 'KNAPSACK_PRO_MODIFY_DEFAULT_RSPEC_FORMATTERS' => false })
|
7
|
+
|
8
|
+
require KnapsackPro.root + '/lib/knapsack_pro/formatters/rspec_queue_summary_formatter'
|
9
|
+
end
|
10
|
+
|
2
11
|
describe '.run' do
|
3
12
|
let(:test_suite_token_rspec) { 'fake-token' }
|
4
13
|
let(:queue_id) { 'fake-queue-id' }
|
@@ -21,13 +30,26 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
21
30
|
end
|
22
31
|
|
23
32
|
context 'when args provided' do
|
24
|
-
|
33
|
+
context 'when format param is not provided' do
|
34
|
+
let(:args) { '--example-arg example-value' }
|
25
35
|
|
26
|
-
|
27
|
-
|
28
|
-
|
36
|
+
it 'uses default formatter progress' do
|
37
|
+
result = double
|
38
|
+
expect(described_class).to receive(:run_tests).with(runner, true, ['--example-arg', 'example-value', '--format', 'progress', '--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter', '--default-path', 'fake-test-dir'], 0, []).and_return(result)
|
29
39
|
|
30
|
-
|
40
|
+
expect(subject).to eq result
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when format param is provided' do
|
45
|
+
let(:args) { '--format documentation' }
|
46
|
+
|
47
|
+
it 'uses provided format param instead of default formatter progress' do
|
48
|
+
result = double
|
49
|
+
expect(described_class).to receive(:run_tests).with(runner, true, ['--format', 'documentation', '--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter', '--default-path', 'fake-test-dir'], 0, []).and_return(result)
|
50
|
+
|
51
|
+
expect(subject).to eq result
|
52
|
+
end
|
31
53
|
end
|
32
54
|
end
|
33
55
|
|
@@ -36,7 +58,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
36
58
|
|
37
59
|
it do
|
38
60
|
result = double
|
39
|
-
expect(described_class).to receive(:run_tests).with(runner, true, ['--default-path', 'fake-test-dir'], 0, []).and_return(result)
|
61
|
+
expect(described_class).to receive(:run_tests).with(runner, true, ['--format', 'progress', '--format', 'KnapsackPro::Formatters::RSpecQueueSummaryFormatter', '--default-path', 'fake-test-dir'], 0, []).and_return(result)
|
40
62
|
|
41
63
|
expect(subject).to eq result
|
42
64
|
end
|
@@ -85,6 +107,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
85
107
|
let(:exit_code) { 0 }
|
86
108
|
|
87
109
|
it do
|
110
|
+
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
|
88
111
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
89
112
|
expect(described_class).to receive(:exit).with(exitstatus)
|
90
113
|
|
@@ -96,6 +119,7 @@ describe KnapsackPro::Runners::Queue::RSpecRunner do
|
|
96
119
|
let(:exit_code) { double }
|
97
120
|
|
98
121
|
it do
|
122
|
+
expect(KnapsackPro::Formatters::RSpecQueueSummaryFormatter).to receive(:print_summary)
|
99
123
|
expect(KnapsackPro::Report).to receive(:save_node_queue_to_api)
|
100
124
|
expect(described_class).to receive(:exit).with(exit_code)
|
101
125
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knapsack_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.33.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- lib/knapsack_pro/crypto/decryptor.rb
|
245
245
|
- lib/knapsack_pro/crypto/digestor.rb
|
246
246
|
- lib/knapsack_pro/crypto/encryptor.rb
|
247
|
+
- lib/knapsack_pro/formatters/rspec_queue_summary_formatter.rb
|
247
248
|
- lib/knapsack_pro/logger_wrapper.rb
|
248
249
|
- lib/knapsack_pro/presenter.rb
|
249
250
|
- lib/knapsack_pro/queue_allocator.rb
|