Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement System Environment Extension #633

Merged
merged 1 commit into from
Feb 12, 2019

Conversation

LeoColman
Copy link
Member

@LeoColman LeoColman commented Feb 1, 2019

This commit implements the System Environment Extensions. With some extension functions and a listener, this commit enables System Environment Override by users, something only possible via reflection.

An special attention is needed to the system environments, as they're susceptible to race conditions. This was specified in the documentations.

This commit also fixes a small issue with SystemProperties extension, in which they wouldn't accept a suspended function. A test for that behavior was added.

This commit also renames the tests package, to stop stacktrace filtering, so that the error is clear whenever one of these tests fail.

Implements #623

@LeoColman
Copy link
Member Author

@sksamuel
Initial implementation. Tell me what you think about it so far

@sksamuel
Copy link
Member

sksamuel commented Feb 1, 2019

We can't use suspend in the extensions.
If you do this:

suspend fun <T> withSystemProperties(props: List<Pair<String, String?>>, thunk: suspend () -> T): T {
    return withSystemProperties(props.toMap(), thunk)
}

Then you can't do this use this in another lambda.

@LeoColman
Copy link
Member Author

If we don't let them suspend, we won't be able to use them in tests. I caught this scenario when trying to write ShouldSpec. Could you give me an example of what what would be a bad case to use it this way?

In ShouldSpec I tried something like:

"Foo" {
    withEnvironment("Boo", "Bar") {
        should("FAR") {

        }
    }
}

@sksamuel
Copy link
Member

sksamuel commented Feb 1, 2019

I use them inside the tests, not outside.

@sksamuel
Copy link
Member

sksamuel commented Feb 1, 2019

Try doing, collections.forEach { withSysProp { ... } }

@LeoColman
Copy link
Member Author

What if we make them inline?
Similar to how it is for shouldThrowAny and similars?

@sksamuel
Copy link
Member

sksamuel commented Feb 1, 2019

If you have a suspend function, and you pass it into a non suspend lambda, the compiler can't reason about when it will be executed. Even if the lambda is currently inside a coroutine scope, there's no saying when that lambda will be invoked.

@LeoColman
Copy link
Member Author

I think that shouldThrow works nice in this sense

@sksamuel
Copy link
Member

sksamuel commented Feb 2, 2019

I don't understand ?

@LeoColman
Copy link
Member Author

LeoColman commented Feb 2, 2019 via email

@sksamuel
Copy link
Member

sksamuel commented Feb 2, 2019 via email

@LeoColman LeoColman force-pushed the feature/623-system-environment-extensions branch from 3b36778 to 27dff14 Compare February 7, 2019 17:08
@LeoColman LeoColman changed the title WIP: Implement System Environment Extension Implement System Environment Extension Feb 7, 2019
@LeoColman
Copy link
Member Author

@sksamuel I think this is the version I'm comfortable with.

@LeoColman
Copy link
Member Author

I'm trying to verify why app veyor is failing. I think it's resetting my environment

@LeoColman LeoColman force-pushed the feature/623-system-environment-extensions branch from 27dff14 to 611294f Compare February 8, 2019 16:21
@LeoColman
Copy link
Member Author

@sksamuel
One thing I"m in doubt:
Do we need a version for each scope? I was thinking that maybe TestLevel would suffice, as it can also be used in ProjectLevel.

Ok, the function will be called more times than it should, but this will avoid confusion, no?

@LeoColman
Copy link
Member Author

(This is the reason I didn't add the others)

@LeoColman
Copy link
Member Author

LeoColman commented Feb 11, 2019

@sksamuel SystemEnvironmentProjectListener added. However, I have no idea how to test it. It would dirty any other tests, and make them too coupled

@sksamuel
Copy link
Member

In the past I've done this by making a new sub module. Like I did for parallelisation.

@LeoColman
Copy link
Member Author

I don't know if there's a problem to dirty context with a very specific variable tho... For instance, just a foo in the system environment.

Do you think it's too much of an issue?

@LeoColman LeoColman force-pushed the feature/623-system-environment-extensions branch from 611294f to 009227a Compare February 11, 2019 14:41
@LeoColman
Copy link
Member Author

I added the test while dirtying the context.
Tell me if you're too much against it, and I'll create a module if necessary.

@LeoColman
Copy link
Member Author

Oh, I just saw that you said this test is not completely necessary. I'll remove it, as I believe that this kind of behavior was already tested in the other functions, and project listener execution is also already tested.

This commit implements the System Environment Extensions. With some extension functions and a listener, this commit enables System Environment Override by users, something only possible via reflection.

An special attention is needed to the system environments, as they're susceptible to race conditions. This was specified in the documentations.

This commit also fixes a small issue with SystemProperties extension, in which they wouldn't accept a suspended function. A test for that behavior was added.

This commit also renames the tests package, to stop stacktrace filtering, so that the error is clear whenever one of these tests fail.

Implements #623
@LeoColman LeoColman force-pushed the feature/623-system-environment-extensions branch from 009227a to 4602970 Compare February 11, 2019 14:48
@LeoColman
Copy link
Member Author

@sksamuel
Are you ok with these changes now?

@sksamuel
Copy link
Member

sksamuel commented Feb 12, 2019 via email

@LeoColman
Copy link
Member Author

Great. Merging this and doing the same to SecurityManager extension

@LeoColman LeoColman merged commit 27c8ab1 into master Feb 12, 2019
@LeoColman LeoColman deleted the feature/623-system-environment-extensions branch February 12, 2019 14:24
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.

2 participants