Comments (4)
@mookerji are you running the tests concurrently per chance? My QuickCheck tests haven't failed with that kind of error.
from envy.
For something similar I've been recommended "compile with -threaded" though
don't know why.
On Dec 17, 2015 7:50 PM, "Bhaskar Mookerji" [email protected]
wrote:
We found a race condition error while trying to write environmental
unit/property tests. This is likely more of a problem underlying
System.Environment, but I'm wondering if there's a way to deal with it
within Envy. Here's an example definition:module Types where
import BasicPreludeimport System.Envy
data Conf = Conf
{ _cConfFile :: Maybe String
, cPort :: Maybe Word32
, cTimeout :: Maybe Word32
} deriving ( Eq, Show )
instance FromEnv Conf where
fromEnv =
Conf <$>
envMaybe "CONFFILE" <>
envMaybe "PORT" <>
envMaybe "TIMEOUT"
instance ToEnv Conf where
toEnv Conf{..} =
makeEnv [ "CONFFILE" .= _cConfFile
, "PORT" .= _cPort
, "TIMEOUT" .= _cTimeout
]and an example test...
module Test
( tests
) where
import BasicPreludeimport Data.Textimport System.Environmentimport System.Envyimport Test.Tastyimport Test.Tasty.HUnit
testEnv :: TestTree
testEnv =
testGroup "Environmental configuration unit test"
[ testCase "Empty configuration" $ do
unsetEnv "SKYLARK_CONFFILE"
unsetEnv "SKYLARK_PORT"
unsetEnv "SKYLARK_TIMEOUT"
c <- decodeEnv :: IO (Either String Conf)
c @?= Right Conf { _cConfFile = Nothing
, _cPort = Nothing
, _cTimeout = Nothing
}
, testCase "Port and Timeout" $ do
unsetEnv "SKYLARK_CONFFILE"
setEnv "SKYLARK_PORT" "1"
setEnv "SKYLARK_TIMEOUT" "1"
c <- decodeEnv :: IO (Either String Conf)
c @?= Right Conf { _cConfFile = Nothing
, _cPort = Just 1
, _cTimeout = Just 1
}
]This test can sometimes pass, or it fail, with the decoded environment in
one test case being not the one set in that specific test case. For
example, the first case unsetting the environmental variables can instead
read the values set in the second test case. This also appears with a
Quickcheck not too different from the one committed with Envy (
https://gist.github.com/mookerji/d6c9fe48bc35e16bd5690).—
Reply to this email directly or view it on GitHub
#6.
from envy.
@dmjio Indeed! I thought that I had removed the threaded flags (I know) and had it still fail, but I must have hallucinated. Removing that flag indeed fixed the problem (see: https://github.com/swift-nav/skylark-core/pull/15/files).
That being said, in a more abstract sense, I feel like you'd want still want some notion of thread safety when calling out for environmental variables?
from envy.
@mookerji for setting them, possibly, if what you're doing isn't simple. But that should be up to the user IMO.
from envy.
Related Issues (20)
- Generics would be sweet... HOT 4
- Allow using unit as an environment variable HOT 4
- Indirect environment variables HOT 1
- Generics without def config HOT 9
- ToEnv purpose HOT 1
- write against MonadIO
- Error Compiling Example Program HOT 1
- No `Var` instance for `Last` HOT 1
- fromVar should return an Either String a HOT 3
- Dont't make implementors of FromEnv instance think of the default value HOT 7
- instances for tuples HOT 4
- Question: Semantics of `envMaybe` HOT 3
- provide a way to extract/print the names of environment variables used?
- Constraints on base are incorrect for 2.0 and 2.1 HOT 3
- Examples with DefConfig don't work
- envy-2.0.0.0 and 2.1.0.0: metadata revisions published to Hackage HOT 1
- Poor error messages for bool variables HOT 2
- What is the proper way of grouping env vars into product Haskell types?
- Relax dependency on bytestring HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from envy.