• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
How to Test Asynchronous Code
 

How to Test Asynchronous Code

on

  • 3,000 views

My nodeconf talk from May 5th. Reworked / better slides are available in my second version of the talk at the BerlinJS group from May 19th.

My nodeconf talk from May 5th. Reworked / better slides are available in my second version of the talk at the BerlinJS group from May 19th.

Statistics

Views

Total Views
3,000
Views on SlideShare
2,999
Embed Views
1

Actions

Likes
2
Downloads
10
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    How to Test Asynchronous Code How to Test Asynchronous Code Document Transcript

    • How to TestAsynchronous Code by Felix Geisendörfer 05.05.2011 (v1)
    • @felixgeTwitter / GitHub / IRC
    • Core Contributor & Module Author node-mysql node-formidable- Joined the mailing list in June 26, 2009- When I joined there where #24 people- Now mailing list has close to 4000 members members- First patch in September 2009
    • File uploading & processing as an infrastructure service for web & mobile applications.- The app we run in production
    • We found node
    • TMWe found node
    • We fell in love
    • We had fun
    • We crashed- Or more specifically: node crashed
    • ~1 .5 Ye Transloadit v1 a rs ag o • Complete failure • Node randomly crashed with: (evcom) recv() Success • A mess of code, hard to maintain * http://transloadit.com/blog/2010/04/to-launch-or-not- 0.1.18- New version of node took out promises- So we thought about refactoring, but ...
    • We had no tests
    • Time to rewrite- RailsConf 09: Robert Martin, "What Killed Smalltalk Could Kill Ruby, Too
    • - We looked at asynchronous testing frameworks- We really wanted to do TDD- But everything we tried was hard
    • db.query(SELECT A, function() { db.query(SELECT B, function() { db.query(SELECT C, function() { db.query(SELECT D, function() { // WTF }); }); }); });- Who here is running node in production?- Raise hands if you have a test suite for your node.js projects- Raise hands if you are happy with it- But why is it so difficult?
    • Fold news paper 7 timesAsk audience to guess the numbers of stacked sheets of papersAsk person to guess right (128) to come up front to rip through the folded paper.What’s this about?- Newspaper can be thought of as a simple computer program managing 7 booleans- Each boolean has a meaningful impact on the behavior of the Software- This means that ripping through it at once, with a single, becomes very difficult- The problem becomes even worse when your variables have more than 2 states-> the euquation turns from being exponential into combinatoric one -> combinatoricexplosion
    • Make it “synchronous”
    • Version 2
    • Well, almost : )
    • N Transloadit v2 ow• Processed many TB of data• Very low bug rate• Clean code base, ~99% test coverage
    • Term microtest vs Unit Test
    • Transloadit Lines of code 13.000 9.750 6.500 3.250 0 library tests library vs test code: 1x : 2.04xLibrary: 6184 LoCTests: 12622 LoCNot included: Fixture data, server configuration, customer website, dependencies wedeveloped
    • Transloadit Lines of code 10.000 7.500 5.000 2.500 0 integration micro integration vs. micro tests: 1x : 4.30xIntegration tests: 2254 LoCMicro Tests: 9695 LoC
    • Transloadit Assertions 3.000 2.250 1.500 750 0 integration micro integration vs. micro tests: 1x : 12.30xIntegration tests: 189 assertsMicro Tests: 2324 asserts
    • node-mysql Lines of code 1.700 1.275 850 425 0 library tests library vs test code: 1x : 1.35xLibrary: 1240 LoC (+600 LoC MySql constants)Tests:Tests: 1673 LoC
    • node-mysql Lines of code 1.300 975 650 325 0 integration micro integration vs micro tests: 1x : 2.89xMicro Tests: 1243 LoCIntegration tests: 430 LoC
    • node-mysql Assertions 400 300 200 100 0 integration micro integration vs micro tests: 1x : 8.15xMicro Tests: 375 assertsIntegration tests: 46 asserts
    • Why do you have brakes in a car? Because then you can drive faster. Kevlin Henneyprobably Kevlin Henney, http://olvemaudal.wordpress.com/2008/04/14/being-agile-no-speeding-please/
    • There really are only two acceptablemodels of development: "think andanalyze" or "years and years oftesting on thousands of machines". Linus Torvalds
    • tl;dr• Don’t use integration tests to show the basic correctness of your software.• Write more microtests.
    • Questions?
    • Questions?