Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Stop looking for bundle.json if an invalid one is found #68

Conversation

srenatus
Copy link
Contributor

The previous behaviour was a little irritating:

If invoked in /some/nested/dir, stable would try to read

/some/nested/dir/bundle.json

and if that failed (because the file didn't exist or was invalid), it
would try to read, subsequently,

/some/nested/bundle.json
/some/bundle.json
/bundle.json

This implied that errors reading any found bundle.json were printed, but
stable kept trying to find a valid one, and eventually, having reached
/bundle.json and assuming it didn't exist, would print

No bundle.json in current working directory or ancestors.

With this change, the logic is different: stable will first try to find
an existing bundle.json, and then attempt to read it. If it fails, it
will not go on, but stop.


Questions

Q: How to test this?

  • Some test that actually invokes the built stable binary given different input situations could include a case of this "nested with broken bundle.json at the bottom" test.
  • The function _locate_bundle() alone could be tested if it was split off the Main actor. Is there a pattern to follow for this?
    • I can't have a constructor for Bundle what would be able to differentiate "keep going" from "stop it" errors. (Where an existing file with a bad format would trigger a stop; and no-file-found would make it "keep going".)
    • Is there such as thing as a static method? Or would we create a "Utils" class for this?

A: I went with the last option, introducing a primitive BundleLocator, and adding tests for that. I've failed to hide it better, as calling it _BundleLocator made it impossible to import it in tests, it seems?

@srenatus srenatus force-pushed the sr/stop-looking-for-bundle.json-if-one-is-found-but-invalid branch from 649be1d to e47c0c4 Compare June 12, 2018 14:28
@mfelsche
Copy link
Contributor

What you could do to test a package private class/actor/whateveryouwantbasically is to create a _test.pony file in the source directory and create a TestList in there, that is not private, that is not a Main actor and that has a make constructor. In this file you can add tests for private apis and add them to the TestList. In the test package you can then instantiate that TestList from _test.pony and run its test.

As an example: https://github.com/ponylang/http/blob/master/http/_test.pony and https://github.com/ponylang/http/blob/master/http/test/main.pony

This way you can have both tests for private and public apis.

@srenatus
Copy link
Contributor Author

@mfelsche thank you! I'll update this PR in a bit. (I had actually looked at that http code yesterday, but it didn't "click". Your words did it, however 👍)

I generally wonder how we approach "hiding" in pony-stable -- I mean, I suppose we could hide much more of its current API surface; but also, I wonder if we need to. I think this isn't meant to be used as a library, so we probably aren't too strict about it. (This could be an argument against adapting BundleLocator to be a private primitive, but I still prefer that, and want to adapt the PR.)

@srenatus
Copy link
Contributor Author

Don't merge ⚠️ this isn't quite right for the case where there's no bundle.json.

Before: it would create one. Now: it fails. The None case of the match here needs adaptation. I'll take care of that.

@srenatus
Copy link
Contributor Author

srenatus commented Jun 13, 2018

✔️ This could be good to go. Since this is currently still lacking any integration-y tests, I suppose we could either scrutinize this PR thoroughly, or hold it off until we have some.

On that topic, I'd be happy to help. It seems like #28 got a little stuck?

⏩ I could imagine either adding tests for Main() with a pre-created Env (pointing to some temp dir, if that's possible), then checking the outcome. Alternatively, building the binary and testing it by some other means (either another ponytest suite, or something like bats) would seem useful as well. What do you think?

@SeanTAllen
Copy link
Member

@srenatus I think that some integration tests as part of this would be a great addition to the PR. If you want to pick up #28, that would be awesome.

@srenatus
Copy link
Contributor Author

@SeanTAllen I've split off getting integration test scaffolding in: #70 ☝️

@SeanTAllen
Copy link
Member

@srenatus sounds good to me.

srenatus added a commit to srenatus/pony-stable that referenced this pull request Jun 19, 2018
…ent)

This is in anticipation of what's going to change in ponylang#68.

Signed-off-by: Stephan Renatus <[email protected]>
srenatus added a commit to srenatus/pony-stable that referenced this pull request Jun 19, 2018
…ent)

This is in anticipation of what's going to change in ponylang#68.

Signed-off-by: Stephan Renatus <[email protected]>
@mfelsche
Copy link
Contributor

@srenatus this needs to be rebased.

@srenatus
Copy link
Contributor Author

@mfelsche thanks for the heads-up; by current plan is leave this rot^Wwaiting until #73 is in -- since that would at least give a little assurance that this isn't breaking the world. :)

srenatus added a commit that referenced this pull request Jul 10, 2018
* Run integration tests in their own temporary directory

Having not found a way to make `@chdir[I32]` or anything like that work,
this commit adds a bash helper script that `cd`s into the directory
before running stable.

Also includes the code changes necessary to create the temporary dir
from pony, and remove it after the tests are done.

The former is done so that upcoming tests can use pony to set up some
initial situation (such as drop a bundle.json).

The cleanup is not done in a `tear_down()` method, because I found no
non-clumsy way to get the reference to the directory into that spot. So
instead, this has a mini-actor that deletes the temp dir when disposed,
and is set up to be called by the test helper.

Note that there's no strict need to run the existing integration tests
in their own temp dirs, so we might make that temp dir passing optional,
maybe, by changing `Exec`'s `cleaner arg from

    cleaner: DisposableActor

to

    cleaner: (DisposableActor | None)

and pass None for help and version.

* Add integration tests for 'stable env'

Turns out this is probably the lowest-hanging fruit right now. This makes
use of the previous commit's "run in temp dir" feature.

* Add test case for invalid bundle.json in nested dir (valid one in parent)

This is in anticipation of what's going to change in #68.

* Run integration tests in separate tmp directory

This adds stable/test/integration/tmp/ as an empty, tracked folder; and
uses that one as base directory for running the integration tests.

It felt a bit cleaner to me than having the temp dirs created in the
top-level folder; also causes less of a mess when debugging integration
tests by disabling the cleanup dispose()'s delete call.

(I suppose it would have been just as good to use /tmp/, but I wasn't
sure what our expectations regarding different operating systems were.)

* Run integration tests sequentially

One of these tests had timed out on circleci. Having flakey tests seems
an annoyance we should try to avoid; but I couldn't reproduce this by
running `make integration` in a loop locally. So, the hypothesis is that
the timeout was no bug in the tests, but a genuine timeout.

Trying to reproduce the test failures locally, I've found that
restricting the memory to 4M (docker's minimum) caused the tests to fail
in a reproducible way.

The integration test binary is now passed `--sequential`, so that the
individual test runs don't compete for resources.

This makes the error _not appear anymore_ in the docker 4M scenario.

This reverts commit 8d8a906.

* Double integration test timeouts

Seems like --sequential alone isn't enough. 200ms doesn't seem too bad,
so let's try this.

* integration: register tmpdir cleanup after creation
* integration/helper.sh: mention chdir issue

Signed-off-by: Stephan Renatus <[email protected]>
The previous behaviour was a little irritating:

If invoked in /some/nested/dir, stable would try to read

    /some/nested/dir/bundle.json

and if that failed (because the file didn't exist or was invalid), it
would try to read, subsequently,

    /some/nested/bundle.json
    /some/bundle.json
    /bundle.json

This implied that errors reading any found bundle.json were printed, but
stable kept trying to find a valid one, and eventually, having reached
/bundle.json and assuming it didn't exist, would print

    No bundle.json in current working directory or ancestors.

With this change, the logic is different: stable will first try to find
an existing bundle.json, and then attempt to read it. If it fails, it
will not go on, but stop.

Signed-off-by: Stephan Renatus <[email protected]>
I'm not sure if this is the best approach, but it seems using primitives
for this is valid (judging from the patterns docs).

Signed-off-by: Stephan Renatus <[email protected]>
@srenatus srenatus force-pushed the sr/stop-looking-for-bundle.json-if-one-is-found-but-invalid branch from 04a3b79 to 3dd2acb Compare July 11, 2018 10:25
@srenatus
Copy link
Contributor Author

@mfelsche rebased and updated ✔️

@mfelsche mfelsche merged commit 4d00c83 into ponylang:master Jul 11, 2018
@mfelsche
Copy link
Contributor

booyah!

@srenatus srenatus deleted the sr/stop-looking-for-bundle.json-if-one-is-found-but-invalid branch July 11, 2018 11:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants