Add "Make Your Tests Deterministic" post #75

Merged
merged 2 commits into from Aug 16, 2012

Conversation

Projects
None yet
3 participants
Contributor

vojtajina commented Aug 13, 2012

and update links in an old post...

Contributor

vojtajina commented Aug 15, 2012

Hey @creationix can anyone review this pull request please ?

@kriskowal kriskowal and 1 other commented on an outdated diff Aug 16, 2012

articles/make-your-tests-deterministic.markdown
@@ -0,0 +1,57 @@
+Title: Make Your Tests Deterministic
+Author: Vojta Jina
+Date: Tue Aug 13 2012 01:12:01 GMT-0800 (PST)
+Node: v0.8.4
+
+
+Non-deterministic issues like [race conditions] or [thread deadlocks] are very difficult to test, because they are by nature hard to reproduce. Fortunately, in the JavaScript world, we only have a single thread, so we are safe, right ? Well, not really because...
@kriskowal

kriskowal Aug 16, 2012

Collaborator

Superfluous space before question mark.

@vojtajina

vojtajina Aug 16, 2012

Contributor

Fixed

@kriskowal kriskowal and 1 other commented on an outdated diff Aug 16, 2012

articles/make-your-tests-deterministic.markdown
@@ -0,0 +1,57 @@
+Title: Make Your Tests Deterministic
+Author: Vojta Jina
+Date: Tue Aug 13 2012 01:12:01 GMT-0800 (PST)
+Node: v0.8.4
+
+
+Non-deterministic issues like [race conditions] or [thread deadlocks] are very difficult to test, because they are by nature hard to reproduce. Fortunately, in the JavaScript world, we only have a single thread, so we are safe, right ? Well, not really because...
+
+**Execution order of callbacks can cause the same race condition issues that plague multi-threaded environments.**
@kriskowal

kriskowal Aug 16, 2012

Collaborator

It might be worth introducing the term datalock, which is distinct from deadlock. Deadlock is not possible in single-threaded JavaScript. Datalock is the occurrence where a program cannot make progress, but the event loop is free. This happens when there are cyclic dependencies among scheduled work. I was introduced to the term by Mark Miller and can ask him for a citation reference.

@vojtajina

vojtajina Aug 16, 2012

Contributor

Let's keep it without datalock term, I don't think it would help understanding this post.

However, I'm interested in the citation reference. I understand the problem, but never heard of this term.

@kriskowal kriskowal and 1 other commented on an outdated diff Aug 16, 2012

articles/make-your-tests-deterministic.markdown
+Date: Tue Aug 13 2012 01:12:01 GMT-0800 (PST)
+Node: v0.8.4
+
+
+Non-deterministic issues like [race conditions] or [thread deadlocks] are very difficult to test, because they are by nature hard to reproduce. Fortunately, in the JavaScript world, we only have a single thread, so we are safe, right ? Well, not really because...
+
+**Execution order of callbacks can cause the same race condition issues that plague multi-threaded environments.**
+
+
+## Example
+
+Let's say we need a function that will return an array of timestamps representing the last modification time of a set of files.
+
+<make-your-tests-deterministic/get-last-modified.js>
+
+To unit test this code, we need to mock out fs module (using real file system would require setting up some initial state, cleaning up afterwards and would make the test slow). That's pretty easy with [node-mocks] - we can use a fake in-memory file system.
@kriskowal

kriskowal Aug 16, 2012

Collaborator

I’d put ticks around module and variable names.

@kriskowal

kriskowal Aug 16, 2012

Collaborator

Typographically, you might consider an em-dash, "—". That’s &mdash; or the equivalent in Unicode. On a Mac, it pops out with option+shift+hyphen. Some Markdown plugins convert -- to an em-dash, though I do not know whether this system supports it.

@vojtajina

vojtajina Aug 16, 2012

Contributor

em-dash looks weird, I used ` - is that what you meant with "tick" ?

Contributor

vojtajina commented Aug 16, 2012

Thanks @kriskowal for suggestions, it's fixed now.

Owner

creationix commented Aug 16, 2012

Thanks a lot @kriskowal! @vojtajina when do you want this published? I'm leaving town in about 30 minutes and won't be back to internet till Saturday afternoon. If Kris merges, it should auto deploy to howtonode, but there is always the chance it goes wrong. As long as you test it locally on the latest wheat, it shouldn't bring the site down.

Contributor

vojtajina commented Aug 16, 2012

I think we can just publish it. It's rebased on the latest master of howtonode.org. I updated my local deps (npm update) and it works fine locally.

Thanks for review, guys.

@creationix creationix added a commit that referenced this pull request Aug 16, 2012

@creationix creationix Merge pull request #75 from vojtajina/add-make-your-tests-deterministic
Add "Make Your Tests Deterministic" post
509eced

@creationix creationix merged commit 509eced into creationix:master Aug 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment