82
Testing of distributed applications Rails Way Con 2011 Jens-Christian Fischer with Michael Mahlberg & Keith Bingman [email protected] @jcfischer Freitag, 3. Juni 2011

Testing distributed, complex web applications

  • View
    3.039

  • Download
    2

Embed Size (px)

DESCRIPTION

As applications grow from single Rails applications to complex systems with multiple, interacting applications & web services, testing becomes more and more difficult. While we can test each application independently, we need to be able to test the full stack. This presentation shows methods, tools and tipps & tricks from testing such a complex application.

Citation preview

Page 1: Testing distributed, complex web applications

Testing of distributed applications

Rails Way Con 2011Jens-Christian Fischer

with Michael Mahlberg & Keith Bingman

[email protected]

@jcfischer

Freitag, 3. Juni 2011

Page 2: Testing distributed, complex web applications

Testing of distributed applications

Rails Way Con 2011Jens-Christian Fischer

with Michael Mahlberg & Keith Bingman

[email protected]

@jcfischer

complex

Freitag, 3. Juni 2011

Page 3: Testing distributed, complex web applications

Agenda

•Background

•What & Why & How of Testing

•Discover the state of your apps

•Make testable apps

Freitag, 3. Juni 2011

Page 4: Testing distributed, complex web applications

why?Freitag, 3. Juni 2011

Page 5: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 6: Testing distributed, complex web applications

we move money

Freitag, 3. Juni 2011

Page 7: Testing distributed, complex web applications

What is behind?

1 Rails app

5 Sinatra apps

1 Ruby daemon

1 VOIP Server

1 Speech Synthesizer

1 SQL Database (Postgres)

1 NoSQL Server (Redis) (with Resque)

Freitag, 3. Juni 2011

Page 8: Testing distributed, complex web applications

Architecture

Freitag, 3. Juni 2011

Page 9: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Freitag, 3. Juni 2011

Page 10: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Freitag, 3. Juni 2011

Page 11: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Voice

Front

Back

Database

Freitag, 3. Juni 2011

Page 12: Testing distributed, complex web applications

SmithKeynesGreenspan

Trichet Volcker Duisenberg

Freitag, 3. Juni 2011

Page 13: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 14: Testing distributed, complex web applications

Testing

Freitag, 3. Juni 2011

Page 15: Testing distributed, complex web applications

The old days

•Simple web apps

•Click through testing

Freitag, 3. Juni 2011

Page 16: Testing distributed, complex web applications

Royce, W. (1970). Managing the development of large software systems. Proceedings of IEEE Wescon.

Testin

g

Freitag, 3. Juni 2011

Page 17: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 18: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 19: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 20: Testing distributed, complex web applications

In Rails—

everything is better

Freitag, 3. Juni 2011

Page 21: Testing distributed, complex web applications

Automated Tests

Unit

Integration

Frontend tests

Freitag, 3. Juni 2011

Page 22: Testing distributed, complex web applications

Complexity

•Modern applications consist of many pieces

•App Servers, DB, NoSQL, WebServices, Telephony, Speech Synthesizers

•HTTP, Line Protocols, JSON, XML, Corba, RMI

Freitag, 3. Juni 2011

Page 23: Testing distributed, complex web applications

What to testRobert „UncleBob“ Martin:

•Unit Tests

•Component Tests

• Integration Tests

•System Test

•Manual Tests

http://stackoverflow.com/questions/2965483

Freitag, 3. Juni 2011

Page 24: Testing distributed, complex web applications

Unit Tests

•Close to 100% code coverage

•Test Driven Development

•Written by Programmers

Freitag, 3. Juni 2011

Page 25: Testing distributed, complex web applications

Component Tests

•Test ~50% of the System

•Cucumber / Selenium / Fitnesse

•Written by QA & Analysts

•Happy Path & some unhappy paths

Freitag, 3. Juni 2011

Page 26: Testing distributed, complex web applications

Integration Tests

•Cover ~20% of system

•Test assembly of components

•Cucumber / Selenium / Fitnesse

•Written by Architects

Freitag, 3. Juni 2011

Page 27: Testing distributed, complex web applications

System Tests

•Cover 10% of the system

•Test the whole system

•Cucumber / Selenium / Fitnesse

•Written by Architects

Freitag, 3. Juni 2011

Page 28: Testing distributed, complex web applications

Manual Tests

•Exploratory Manual Tests

•Manual but not scripted

•Human ingenuity & creativity

Bach, J. (n.d.). Exploratory testing explained. Online: http://www. satisfice. com/articles/et-article. pdf.

Freitag, 3. Juni 2011

Page 29: Testing distributed, complex web applications

Where do we test?

Freitag, 3. Juni 2011

Page 30: Testing distributed, complex web applications

Testing the edges

Freitag, 3. Juni 2011

Page 31: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Freitag, 3. Juni 2011

Page 32: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Freitag, 3. Juni 2011

Page 33: Testing distributed, complex web applications

How do we test?

Freitag, 3. Juni 2011

Page 35: Testing distributed, complex web applications

Tools of the trade

Selenium

Cucumber

Steak

capybara

webkit

zombie

Freitag, 3. Juni 2011

Page 36: Testing distributed, complex web applications

only cover a minimal part

the web frontend, but our apps are so much

more

Freitag, 3. Juni 2011

Page 37: Testing distributed, complex web applications

Decoupling

Systems diverge

APIs diverge

Freitag, 3. Juni 2011

Page 38: Testing distributed, complex web applications

Web Services

Many services outside our control

Freitag, 3. Juni 2011

Page 39: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 40: Testing distributed, complex web applications

Synchronizing

•Tests require complex state across several systems

•Tests involve complex interactions between systems

Freitag, 3. Juni 2011

Page 41: Testing distributed, complex web applications

Questions

Freitag, 3. Juni 2011

Page 42: Testing distributed, complex web applications

Questions to ask

•Development

•Testing

•Production

Freitag, 3. Juni 2011

Page 43: Testing distributed, complex web applications

Development

Is the system I‘m building correct?

Freitag, 3. Juni 2011

Page 44: Testing distributed, complex web applications

Test

Do all the pieces of the system work

together?

Freitag, 3. Juni 2011

Page 45: Testing distributed, complex web applications

Production

Are all parts of my system working?

Freitag, 3. Juni 2011

Page 46: Testing distributed, complex web applications

Development

•Test Driven Development only takes you so far

•Test a single component

•Unit tests in multiple components work, but don‘t „cross the chasm“

Freitag, 3. Juni 2011

Page 47: Testing distributed, complex web applications

Development

•Setting up a complete system for development can be taxing

• pow to the rescue http://pow.cx/

•Foremanhttps://github.com/ddollar/foreman

Freitag, 3. Juni 2011

Page 48: Testing distributed, complex web applications

Testing

• Integration tests need to stress complete application stack

•Does your CI Server handle this?

Freitag, 3. Juni 2011

Page 49: Testing distributed, complex web applications

Outside your app

Freitag, 3. Juni 2011

Page 50: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Freitag, 3. Juni 2011

Page 51: Testing distributed, complex web applications

Volcker Trichet

Duisenberg Keynes Greenspan

SmithRedis

Postgres 9

Freeswitch

Acapela

VAAS

Customer Web Merchant WebWidget Customer Voice

Freitag, 3. Juni 2011

Page 52: Testing distributed, complex web applications

Write Mock Services

• If you don‘t control it, mock it

• „Rails Enterprise ready ™ “

Freitag, 3. Juni 2011

Page 53: Testing distributed, complex web applications

Mock Services

•Allows you to code against a „real“ specification

•Allows you to code against failure of said service

•Gives you a stick to beat up the developers of said service („Rails-Enterprise ready“ ™ )

Freitag, 3. Juni 2011

Page 54: Testing distributed, complex web applications

Making it work

Freitag, 3. Juni 2011

Page 55: Testing distributed, complex web applications

Version Control

Repository setup

One Big repository?

One repository for each component?

Tagging / Syncing

Freitag, 3. Juni 2011

Page 56: Testing distributed, complex web applications

Development Servers

Webrick doesn‘t scale

but:

it‘s „easy“ for Rack based apps

pow by 37 Signals

(Mac Only)

Freitag, 3. Juni 2011

Page 57: Testing distributed, complex web applications

Configuration

Configuring half a dozen applications

Again: Synchronisation

Inject configuration (Example Picky)

http://florianhanke.com/picky/

Freitag, 3. Juni 2011

Page 58: Testing distributed, complex web applications

Production

Is my system working correctly?

Probes

•DTrace (OSX, Solaris)

•Monitoring (Scout, NewRelic)

•Your own probes

Freitag, 3. Juni 2011

Page 59: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 60: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 61: Testing distributed, complex web applications

Car industry

If car manufacturers would build engines the way enterprise IT systems are built, you‘d need to remove the engine from the car and disassemble it completely to find a fault

— @MMahlberg, 2011

Freitag, 3. Juni 2011

Page 62: Testing distributed, complex web applications

OBD• 1996: The OBD-II specification is made mandatory for

all cars sold in the United States.

• 2001: The European Union makes EOBD mandatory for all gasoline (petrol) vehicles sold in the European Union, starting in MY2001 (see European emission standards Directive 98/69/EC [1]).

• 2008: All cars sold in the United States are required to use the ISO 15765-4 [2] signaling standard (a variant of the Controller Area Network (CAN) bus).

http://en.wikipedia.org/wiki/On-board_diagnostics

Freitag, 3. Juni 2011

Page 63: Testing distributed, complex web applications

Solved Problem

Freitag, 3. Juni 2011

Page 64: Testing distributed, complex web applications

Freitag, 3. Juni 2011

Page 65: Testing distributed, complex web applications

http://the-adam.com/adam/rantrave/ibm_360.jpgFreitag, 3. Juni 2011

Page 66: Testing distributed, complex web applications

Diagnosis Channel

•Known from Car / Planes / Mainframes

•Red lights on your dashboard

•Complete diagnosis of system possible

•Complete remote control possible

Freitag, 3. Juni 2011

Page 67: Testing distributed, complex web applications

Rolls Royce

• InFlight Diagnosis of engines remotely

Freitag, 3. Juni 2011

Page 68: Testing distributed, complex web applications

Dashboard

•Look into state of application

•Sanity Checker

Freitag, 3. Juni 2011

Page 69: Testing distributed, complex web applications

Dashboarding

•Extract relevant data from your system

•How many req / s

•How many logins

•Delta / Trends

Freitag, 3. Juni 2011

Page 70: Testing distributed, complex web applications

SanityChecker

•API that allows you to extract the state of your app

•DB there?

•All neighbouring components reachable?

Freitag, 3. Juni 2011

Page 71: Testing distributed, complex web applications

Chaos Monkey

•Random failures

•Better reliability

Freitag, 3. Juni 2011

Page 72: Testing distributed, complex web applications

Build testable apps

•Expose your internals (through APIs)

•Use SOLID design

• Single Responsibility Principle

• Open Closed

• Liskov Substitution Principle

• Inversion of Control

• Dependency Injection

Freitag, 3. Juni 2011

Page 73: Testing distributed, complex web applications

Testable apps

•Obey the abstraction layers

• keep each method at it‘s own level of abstraction

Freitag, 3. Juni 2011

Page 74: Testing distributed, complex web applications

Build probe-able apps

•Measure APIs

$  rails  console  production

Freitag, 3. Juni 2011

Page 75: Testing distributed, complex web applications

Build controllable apps

•Call functionality of the app

•Create new user

•Create transactions

•Delete stuff

•Do stuff

• ...

Freitag, 3. Juni 2011

Page 76: Testing distributed, complex web applications

Test user / Magic

• In „Enterprise“ systems:

•Test Company

•Test User

•Test Accounts

•Are those in production system?

•Do everything - or not quite?

Freitag, 3. Juni 2011

Page 77: Testing distributed, complex web applications

Use production data in development / test

Freitag, 3. Juni 2011

Page 78: Testing distributed, complex web applications

Wrapping up

Freitag, 3. Juni 2011

Page 79: Testing distributed, complex web applications

What & Why & How of Testing

Discover the state of your apps

Make testable apps

Freitag, 3. Juni 2011

Page 80: Testing distributed, complex web applications

Thank you!

Freitag, 3. Juni 2011

Page 82: Testing distributed, complex web applications

License

http://creativecommons.org/licenses/by-nc-sa/2.5/ch/Freitag, 3. Juni 2011