Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dotmpe
Copy link
Contributor

@dotmpe dotmpe commented Sep 30, 2017

Looked at and implemented an initial solution for the first unassigned issue in [sstephenson/bats#196]

@mbland
Copy link
Contributor

mbland commented Sep 30, 2017

By way of review, I've pushed a new branch, dup-warning-#9, whereby I've rebased this branch onto mbland-optimized from #8. First it fixes a bug whereby no warning was emitted when a test case appeared in between the two duplicates (the pipeline needed sort in between grep and uniq), but otherwise maintains parity with the original while making changes to improve readability and performance.

Each individual commit message explains the rationale for each change. The final message shows that using a while loop instead of a grep pipeline improves performance significantly (the test suite runs ~9% faster on macOS, ~19% faster on Windows under VMWare).

@BvBerkum Let me know if you have any questions or concerns, or how you'd like to proceed. Feel free to cherry-pick my commits onto your branch, or just copy the code. I still hope to merge #8 first, though it's not strictly necessary.

cc: @btamayo

@mbland mbland self-requested a review September 30, 2017 19:25
@mbland
Copy link
Contributor

mbland commented Sep 30, 2017

OK, #8 has been merged, and I've rebased dup-warning-#9 upon it. The conflict in this branch is just where #8 and this PR both added a new test case to the end of test/bats.bats.

@dotmpe
Copy link
Contributor Author

dotmpe commented Oct 2, 2017

Afterwards, I began thinking a bit more about the performance impact. I really just picked up this issue to refamiliarize myself with the BATS core code. Also having recently tried the optimized branch, I've been trying to get a bit more conscious about the resource footprint. E.g. I use a bats dry-run in my GIT pre-commit to verify the test cases parse OK. And on a modern macbook or cloud server its easy to forget what a little shell scripting can cost.. Anyway.

I will return to the code during the week or next weekend probably, and look at your fixes @mbland. And try see about any performance hit in addition.

@mbland
Copy link
Contributor

mbland commented Oct 7, 2017

@BvBerkum Have you the bandwidth to bang on this this weekend? Don't want to rush you, but I'd like to keep the momentum towards v1.0.0 going.

Also, to the point about performance: I didn't start thinking about it until I had several hundred test cases for mbland/go-script-bash that were taking about an hour to run on Windows—then I thought about it a lot. ;-) Certainly the optimization techniques I applied to Bats would be overkill in most scripts, but for a test framework that executes DEBUG traps and other frequently-looping operations, they can make the difference between people writing and running tests, or deciding the wait isn't worth the effort.

Hence my obsession with performance in this context, in pursuit of the larger goal of "making the right thing the easy thing."

@mbland mbland added this to the v1.0.0 milestone Oct 9, 2017
@dotmpe
Copy link
Contributor Author

dotmpe commented Oct 10, 2017

I only found to time to mull it over a bit, but you're right, I'm too easily distracted by details. I'm talking about parsing 50 files with 300 tests or so.

Rebasing on mbland-optimized shouldn't be a problem. I'll get to it one of these days.

@mbland
Copy link
Contributor

mbland commented Oct 10, 2017

No worries, but two quick points:

dotmpe and others added 6 commits October 14, 2017 11:45
Moving the first test case in between the two duplicate test cases
caused a test failure, revealing the need to add `sort` in between
`grep` and `uniq -d`.
Extracted this function to encapsulate the operation prior to future
refactoring. It also fits better with the surrounding code style,
whereby small functions provide documentation, even for single-line
commands.
This achieves the same effect without launching a new process for the
`test` command. Also, using a multi-line `if` statement and keeping the
line length to under 80 columns helps with readability.
The `case` statement was a little difficult to read, and as it turns
out, using `$FIXTURE_ROOT/duplicate-tests.bats` enables us to make an
exact string comparison.

Also added some `printf` statements to see more clearly what the results
were when a test assertion fails.
The big thing I did in bats-core#8 was to eliminate as many
subshells, pipelines, and subprocesses as possible. Even though we
normally rely write scripts because of these features, in a framework
like Bats, they add up quickly and can have a big performance
impact—especially on Windows, especially when running virtualized.

Conseqently, replacing the previous `grep` pipeline with a `while` loop
causes the suite to run ~9% faster on macOS, and ~19% faster on Windows
(running under VMWare).

The following times were collected by running `time bin/bats test` on a:
  MacBook Pro
  Processor: 2.9 GHz Intel Core i5
  RAM: 8 GB 1867 MHz DDR3

Bash 4.4.12(1)-release running on macOS 10.12.6
-----------------------------------------------
Before this change:

  47 tests, 0 failures

  real    0m4.703s
  user    0m2.712s
  sys     0m1.570s

After this change:

  47 tests, 0 failures

  real    0m4.312s
  user    0m2.369s
  sys     0m1.166s

Git for Windows Bash 4.4.12(1)-release running on Windows 10 under
VMWare Fusion 8.5.8
------------------------------------------------------------------
Before this change:

  47 tests, 0 failures

  real    0m19.832s
  user    0m4.170s
  sys     0m8.893s

After this change:

  47 tests, 0 failures

  real    0m16.675s
  user    0m3.463s
  sys     0m7.297s
@mbland mbland mentioned this pull request Oct 20, 2017
6 tasks
@sublimino
Copy link
Member

Hello @BvBerkum - if you've got the bandwidth to rebase @mbland's changes on to this branch please do so :)

Otherwise either @mbland or I will create a new PR for these commits some time next week so we can move towards https://github.com/bats-core/bats-core/milestone/1 :)

@dotmpe dotmpe force-pushed the features/duplicate-test-warning branch from 5f96384 to fc41eb7 Compare March 18, 2018 03:06
@dotmpe dotmpe requested a review from a team as a code owner March 18, 2018 03:06
@dotmpe
Copy link
Contributor Author

dotmpe commented Mar 18, 2018

There you are. I'd hate to be the hold-up since I see the issues piling up again.

I'll keep out an eye for anything else to do, if I can follow what the current focus is. I'm happy with my fork and it has been easy to integrate recent upstream changes, but hopefully Bats can get some new releases out and we can get everything together and not end up with Bats dialects or insufficiently specified versions.

@nkakouros
Copy link
Contributor

On top of @mbland's version, a few more tiny savings can be achieved if the inner while loop is removed. Like a couple of tens of milliseconds.

@sublimino
Copy link
Member

sublimino commented Apr 2, 2018

@tterranigma I think that removing the inner while loop relies on spaces not being present in the test names. Apologies if I'm incorrect, I think for that change we'd have to add a test case with "gizmo test" and "gizmo test 2" to verify. My thinking:

line="andy"
test_names=("andy 2")
if [[ " ${test_names[*]} " == *" $line "* ]]; then echo match; fi

As for this change: LGTM, /cc @mbland

@nkakouros
Copy link
Contributor

@sublimino By the time the inner loop is hit, the test names are already converted to function names with dashes and underscores. The Bash variable substitutions a few lines above just capture these function names that are passed as an rfugment to bats_test_function. I think the conditional "hack" to replace the loop will work each time in this case.

@sublimino
Copy link
Member

@tterranigma my mistake then, sorry!

@dotmpe
Copy link
Contributor Author

dotmpe commented Apr 15, 2018

@mbland
I see a lot more changes now. I'm a bit confused what the release and/or development branch is. I'd be happy to sort some things out, but I need to know which branch to refer so all changes are tracked.

In retrospect it looks to me like the feature has significantly progressed from my initial features/duplicate-test-warning. I'm sorry for the confusion and time, please close the PR or advice. tia.

@mbland
Copy link
Contributor

mbland commented May 30, 2018

@BvBerkum Sorry to leave you hanging; things were crazy in April. You should be able to merge dup-warning-#9 into your branch, then merge the current master into it. There'll be a small conflict (a few new test cases), easy to resolve.

If you'd rather I do it, I can do it too.

@dotmpe
Copy link
Contributor Author

dotmpe commented Jun 5, 2018

@mbland done

@mbland mbland merged commit 1ae8b50 into bats-core:master Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants