How to Test Asynchronous Code

Felix Geisendörfer
Felix GeisendörferChief Quality Enforcer at Debuggable Limited

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.

How to Test
Asynchronous Code
     by Felix Geisendörfer




                             05.05.2011 (v1)
@felixge

Twitter / 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
How to Test Asynchronous Code
How to Test Asynchronous Code
File uploading & processing as an infrastructure
              service for web & mobile applications.


- The app we run in production
We found node
TM




We 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 times
Ask audience to guess the numbers of stacked sheets of papers
Ask 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 -> combinatoric
explosion
How to Test Asynchronous Code
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
How to Test Asynchronous Code
How to Test Asynchronous Code
How to Test Asynchronous Code
How to Test Asynchronous Code
How to Test Asynchronous Code
How to Test Asynchronous Code
Transloadit
                                         Lines of code

                        13.000

                         9.750

                         6.500

                         3.250

                             0
                                     library         tests

                      library vs test code: 1x : 2.04x
Library: 6184 LoC
Tests: 12622 LoC

Not included: Fixture data, server configuration, customer website, dependencies we
developed
Transloadit
                                        Lines of code

                         10.000

                          7.500

                          5.000

                          2.500

                              0
                                  integration       micro

                 integration vs. micro tests: 1x : 4.30x
Integration tests: 2254 LoC
Micro Tests: 9695 LoC
Transloadit
                                            Assertions

                           3.000

                           2.250

                           1.500

                             750

                                 0
                                     integration         micro

                 integration vs. micro tests: 1x : 12.30x
Integration tests: 189 asserts
Micro Tests: 2324 asserts
How to Test Asynchronous Code
node-mysql
                                        Lines of code

                         1.700

                         1.275

                           850

                           425

                             0
                                    library          tests

                      library vs test code: 1x : 1.35x
Library: 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.89x
Micro Tests: 1243 LoC
Integration tests: 430 LoC
node-mysql
                                             Assertions

                                400

                                300

                                200

                                100

                                  0
                                      integration         micro

                  integration vs micro tests: 1x : 8.15x
Micro Tests: 375 asserts
Integration tests: 46 asserts
Why do you have brakes in a car?
    Because then you can drive faster.

                                                             Kevlin Henney



probably Kevlin Henney, http://olvemaudal.wordpress.com/2008/04/14/being-agile-no-
speeding-please/
There really are only two acceptable
models of development: "think and
analyze" or "years and years of
testing 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?
How to Test Asynchronous Code
How to Test Asynchronous Code

Recommended

How to Test Asynchronous Code (v2) by
How to Test Asynchronous Code (v2)How to Test Asynchronous Code (v2)
How to Test Asynchronous Code (v2)Felix Geisendörfer
4.8K views41 slides
Node.js Workshop - Sela SDP 2015 by
Node.js Workshop  - Sela SDP 2015Node.js Workshop  - Sela SDP 2015
Node.js Workshop - Sela SDP 2015Nir Noy
937 views98 slides
Java Runtime: повседневные обязанности JVM by
Java Runtime: повседневные обязанности JVMJava Runtime: повседневные обязанности JVM
Java Runtime: повседневные обязанности JVModnoklassniki.ru
3.7K views32 slides
NodeJS: an Introduction by
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an IntroductionRoberto Casadei
213 views32 slides
Build, logging, and unit test tools by
Build, logging, and unit test toolsBuild, logging, and unit test tools
Build, logging, and unit test toolsAllan Huang
1.1K views36 slides
Grand Central Dispatch Design Patterns by
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsRobert Brown
10.6K views39 slides

More Related Content

What's hot

Introduction to NodeJS by
Introduction to NodeJSIntroduction to NodeJS
Introduction to NodeJSCere Labs Pvt. Ltd
844 views16 slides
Original slides from Ryan Dahl's NodeJs intro talk by
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
2.1K views69 slides
Asynchronous I/O in NodeJS - new standard or challenges? by
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Dinh Pham
2.4K views26 slides
Java New Evolution by
Java New EvolutionJava New Evolution
Java New EvolutionAllan Huang
1.4K views76 slides
Node.js by
Node.jsNode.js
Node.jskrishnapriya Tadepalli
526 views37 slides
Nodejs Event Driven Concurrency for Web Applications by
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web ApplicationsGanesh Iyer
7.4K views83 slides

What's hot(20)

Original slides from Ryan Dahl's NodeJs intro talk by Aarti Parikh
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
Aarti Parikh2.1K views
Asynchronous I/O in NodeJS - new standard or challenges? by Dinh Pham
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
Dinh Pham2.4K views
Java New Evolution by Allan Huang
Java New EvolutionJava New Evolution
Java New Evolution
Allan Huang1.4K views
Nodejs Event Driven Concurrency for Web Applications by Ganesh Iyer
Nodejs Event Driven Concurrency for Web ApplicationsNodejs Event Driven Concurrency for Web Applications
Nodejs Event Driven Concurrency for Web Applications
Ganesh Iyer7.4K views
Non-blocking synchronization — what is it and why we (don't?) need it by Alexey Fyodorov
Non-blocking synchronization — what is it and why we (don't?) need itNon-blocking synchronization — what is it and why we (don't?) need it
Non-blocking synchronization — what is it and why we (don't?) need it
Alexey Fyodorov2K views
Intro to node and non blocking io by Amy Hua
Intro to node and non blocking ioIntro to node and non blocking io
Intro to node and non blocking io
Amy Hua8K views
Vert.x v3 - high performance polyglot application toolkit by Sages
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkit
Sages2.9K views
Grand Central Dispatch by cqtt191
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
cqtt1916.4K views
JavaOne 2011 - JVM Bytecode for Dummies by Charles Nutter
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
Charles Nutter8K views
Node.js and How JavaScript is Changing Server Programming by Tom Croucher
Node.js and How JavaScript is Changing Server Programming  Node.js and How JavaScript is Changing Server Programming
Node.js and How JavaScript is Changing Server Programming
Tom Croucher10.4K views
Introduction to node.js by Dinesh U
Introduction to node.jsIntroduction to node.js
Introduction to node.js
Dinesh U641 views
Philly Tech Week Introduction to NodeJS by Ross Kukulinski
Philly Tech Week Introduction to NodeJSPhilly Tech Week Introduction to NodeJS
Philly Tech Week Introduction to NodeJS
Ross Kukulinski484 views
Twisted: a quick introduction by Robert Coup
Twisted: a quick introductionTwisted: a quick introduction
Twisted: a quick introduction
Robert Coup5.8K views
node.js: Javascript's in your backend by David Padbury
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
David Padbury12.6K views
Introduction to node.js by jacekbecela
Introduction to node.jsIntroduction to node.js
Introduction to node.js
jacekbecela9.4K views

Viewers also liked

Intro to Application Express by
Intro to Application ExpressIntro to Application Express
Intro to Application ExpressJosé Angel Ibarra Espinosa
2.2K views109 slides
Asynchronous Programming, Analysis and Testing with State Machines by
Asynchronous Programming, Analysis and Testing with State MachinesAsynchronous Programming, Analysis and Testing with State Machines
Asynchronous Programming, Analysis and Testing with State MachinesPantazis Deligiannis
922 views49 slides
Jsconf asia pm2 by
Jsconf asia pm2Jsconf asia pm2
Jsconf asia pm2Alexandre Strzelewicz
1K views48 slides
Unit test by
Unit testUnit test
Unit testTran Duc
760 views43 slides
Node by
NodeNode
NodeArjun Raj
4.2K views18 slides
Application express by
Application expressApplication express
Application expressAntony Alex
1.2K views37 slides

Viewers also liked(19)

Asynchronous Programming, Analysis and Testing with State Machines by Pantazis Deligiannis
Asynchronous Programming, Analysis and Testing with State MachinesAsynchronous Programming, Analysis and Testing with State Machines
Asynchronous Programming, Analysis and Testing with State Machines
Unit test by Tran Duc
Unit testUnit test
Unit test
Tran Duc760 views
Application express by Antony Alex
Application expressApplication express
Application express
Antony Alex1.2K views
Unit-Testing Your Legacy JavaScript by Rob Myers
Unit-Testing Your Legacy JavaScriptUnit-Testing Your Legacy JavaScript
Unit-Testing Your Legacy JavaScript
Rob Myers1.3K views
Testing with Express, Mocha & Chai by Joerg Henning
Testing with Express, Mocha & ChaiTesting with Express, Mocha & Chai
Testing with Express, Mocha & Chai
Joerg Henning1.5K views
Advanced Javascript Unit Testing by Lars Thorup
Advanced Javascript Unit TestingAdvanced Javascript Unit Testing
Advanced Javascript Unit Testing
Lars Thorup1.8K views
Avoiding Callback Hell with Async.js by cacois
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
cacois21.4K views
Unit Testing Express and Koa Middleware in ES2015 by Morris Singer
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
Morris Singer5.2K views
Mocha Testing by Erick Aky
Mocha TestingMocha Testing
Mocha Testing
Erick Aky652 views
AJS — Asynchronous Templating in Node by Evan Owen
AJS — Asynchronous Templating in NodeAJS — Asynchronous Templating in Node
AJS — Asynchronous Templating in Node
Evan Owen4.1K views
Unit testing JavaScript using Mocha and Node by Josh Mock
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
Josh Mock11.2K views
Unit Testing Express Middleware by Morris Singer
Unit Testing Express MiddlewareUnit Testing Express Middleware
Unit Testing Express Middleware
Morris Singer22.1K views
How to Successfully Run a Remote Team by Weekdone.com
How to Successfully Run a Remote TeamHow to Successfully Run a Remote Team
How to Successfully Run a Remote Team
Weekdone.com282.9K views
The Great State of Design with CSS Grid Layout and Friends by Stacy Kvernmo
The Great State of Design with CSS Grid Layout and FriendsThe Great State of Design with CSS Grid Layout and Friends
The Great State of Design with CSS Grid Layout and Friends
Stacy Kvernmo2.1M views

Similar to How to Test Asynchronous Code

FreeSWITCH as a Microservice by
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a MicroserviceEvan McGee
3.4K views24 slides
Node.js meetup at Palo Alto Networks Tel Aviv by
Node.js meetup at Palo Alto Networks Tel AvivNode.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel AvivRon Perlmuter
868 views62 slides
Learn OpenStack from trystack.cn ——Folsom in practice by
Learn OpenStack from trystack.cn  ——Folsom in practiceLearn OpenStack from trystack.cn  ——Folsom in practice
Learn OpenStack from trystack.cn ——Folsom in practiceOpenCity Community
1.7K views26 slides
Varnish Cache by
Varnish CacheVarnish Cache
Varnish CacheMike Willbanks
5.1K views46 slides
Integrating OpenStack To Existing Infrastructure by
Integrating OpenStack To Existing InfrastructureIntegrating OpenStack To Existing Infrastructure
Integrating OpenStack To Existing InfrastructureHui Cheng
3.7K views26 slides
Resilience Testing by
Resilience Testing Resilience Testing
Resilience Testing Ran Levy
305 views33 slides

Similar to How to Test Asynchronous Code(20)

FreeSWITCH as a Microservice by Evan McGee
FreeSWITCH as a MicroserviceFreeSWITCH as a Microservice
FreeSWITCH as a Microservice
Evan McGee3.4K views
Node.js meetup at Palo Alto Networks Tel Aviv by Ron Perlmuter
Node.js meetup at Palo Alto Networks Tel AvivNode.js meetup at Palo Alto Networks Tel Aviv
Node.js meetup at Palo Alto Networks Tel Aviv
Ron Perlmuter868 views
Learn OpenStack from trystack.cn ——Folsom in practice by OpenCity Community
Learn OpenStack from trystack.cn  ——Folsom in practiceLearn OpenStack from trystack.cn  ——Folsom in practice
Learn OpenStack from trystack.cn ——Folsom in practice
OpenCity Community1.7K views
Integrating OpenStack To Existing Infrastructure by Hui Cheng
Integrating OpenStack To Existing InfrastructureIntegrating OpenStack To Existing Infrastructure
Integrating OpenStack To Existing Infrastructure
Hui Cheng3.7K views
Resilience Testing by Ran Levy
Resilience Testing Resilience Testing
Resilience Testing
Ran Levy305 views
WORKSHOP: Microservices as Containers on AWS by Casey Lee
WORKSHOP: Microservices as Containers on AWSWORKSHOP: Microservices as Containers on AWS
WORKSHOP: Microservices as Containers on AWS
Casey Lee205 views
Scaling a MeteorJS SaaS app on AWS by Brett McLain
Scaling a MeteorJS SaaS app on AWSScaling a MeteorJS SaaS app on AWS
Scaling a MeteorJS SaaS app on AWS
Brett McLain1.8K views
Clustrix Database Percona Ruby on Rails benchmark by Clustrix
Clustrix Database Percona Ruby on Rails benchmarkClustrix Database Percona Ruby on Rails benchmark
Clustrix Database Percona Ruby on Rails benchmark
Clustrix 2.6K views
(ARC309) Getting to Microservices: Cloud Architecture Patterns by Amazon Web Services
(ARC309) Getting to Microservices: Cloud Architecture Patterns(ARC309) Getting to Microservices: Cloud Architecture Patterns
(ARC309) Getting to Microservices: Cloud Architecture Patterns
Amazon Web Services10.6K views
Squeak DBX by ESUG
Squeak DBXSqueak DBX
Squeak DBX
ESUG2.2K views
Integrating OpenStack to Existing infrastructure by laurabeckcahoon
Integrating OpenStack to Existing infrastructureIntegrating OpenStack to Existing infrastructure
Integrating OpenStack to Existing infrastructure
laurabeckcahoon877 views
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194... by Nilesh Panchal
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Nilesh Panchal5K views
Low latency microservices in java QCon New York 2016 by Peter Lawrey
Low latency microservices in java   QCon New York 2016Low latency microservices in java   QCon New York 2016
Low latency microservices in java QCon New York 2016
Peter Lawrey7.3K views
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh... by Ambassador Labs
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
[KubeCon NA 2018] Telepresence Deep Dive Session - Rafael Schloming & Luke Sh...
Ambassador Labs365 views
Perfug 20-11-2019 - Kafka Performances by Florent Ramiere
Perfug 20-11-2019 - Kafka PerformancesPerfug 20-11-2019 - Kafka Performances
Perfug 20-11-2019 - Kafka Performances
Florent Ramiere288 views

More from Felix Geisendörfer

Node.js - As a networking tool by
Node.js - As a networking toolNode.js - As a networking tool
Node.js - As a networking toolFelix Geisendörfer
12.9K views47 slides
Node.js - Best practices by
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practicesFelix Geisendörfer
58.6K views38 slides
Node.js - A practical introduction (v2) by
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)Felix Geisendörfer
4.7K views77 slides
Nodejs a-practical-introduction-oredev by
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
2.9K views59 slides
Building an alarm clock with node.js by
Building an alarm clock with node.jsBuilding an alarm clock with node.js
Building an alarm clock with node.jsFelix Geisendörfer
10.8K views47 slides
Nodejs - A quick tour (v6) by
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Felix Geisendörfer
3.9K views68 slides

More from Felix Geisendörfer(16)

Recently uploaded

Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
66 views46 slides
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
17 views1 slide
Scaling Knowledge Graph Architectures with AI by
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
50 views15 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
38 views43 slides
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism UniverseSimone Puorto
13 views61 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
18 views1 slide

Recently uploaded(20)

Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman38 views
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto13 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10345 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana17 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson126 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker48 views

How to Test Asynchronous Code

  • 1. How to Test Asynchronous Code by Felix Geisendörfer 05.05.2011 (v1)
  • 3. 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
  • 6. File uploading & processing as an infrastructure service for web & mobile applications. - The app we run in production
  • 9. We fell in love
  • 11. We crashed - Or more specifically: node crashed
  • 12. ~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 ...
  • 13. We had no tests
  • 14. Time to rewrite - RailsConf 09: Robert Martin, "What Killed Smalltalk Could Kill Ruby, Too
  • 15. - We looked at asynchronous testing frameworks - We really wanted to do TDD - But everything we tried was hard
  • 16. 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?
  • 17. Fold news paper 7 times Ask audience to guess the numbers of stacked sheets of papers Ask 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 -> combinatoric explosion
  • 22. N Transloadit v2 ow • Processed many TB of data • Very low bug rate • Clean code base, ~99% test coverage
  • 23. Term microtest vs Unit Test
  • 30. Transloadit Lines of code 13.000 9.750 6.500 3.250 0 library tests library vs test code: 1x : 2.04x Library: 6184 LoC Tests: 12622 LoC Not included: Fixture data, server configuration, customer website, dependencies we developed
  • 31. Transloadit Lines of code 10.000 7.500 5.000 2.500 0 integration micro integration vs. micro tests: 1x : 4.30x Integration tests: 2254 LoC Micro Tests: 9695 LoC
  • 32. Transloadit Assertions 3.000 2.250 1.500 750 0 integration micro integration vs. micro tests: 1x : 12.30x Integration tests: 189 asserts Micro Tests: 2324 asserts
  • 34. node-mysql Lines of code 1.700 1.275 850 425 0 library tests library vs test code: 1x : 1.35x Library: 1240 LoC (+600 LoC MySql constants)Tests: Tests: 1673 LoC
  • 35. node-mysql Lines of code 1.300 975 650 325 0 integration micro integration vs micro tests: 1x : 2.89x Micro Tests: 1243 LoC Integration tests: 430 LoC
  • 36. node-mysql Assertions 400 300 200 100 0 integration micro integration vs micro tests: 1x : 8.15x Micro Tests: 375 asserts Integration tests: 46 asserts
  • 37. Why do you have brakes in a car? Because then you can drive faster. Kevlin Henney probably Kevlin Henney, http://olvemaudal.wordpress.com/2008/04/14/being-agile-no- speeding-please/
  • 38. There really are only two acceptable models of development: "think and analyze" or "years and years of testing on thousands of machines". Linus Torvalds
  • 39. tl;dr • Don’t use integration tests to show the basic correctness of your software. • Write more microtests.