+ All Categories
Home > Software > Monufacture: Effortless Test Data for MongoDB

Monufacture: Effortless Test Data for MongoDB

Date post: 15-Aug-2015
Category:
Upload: tom-leach
View: 307 times
Download: 2 times
Share this document with a friend
Popular Tags:
23
@tomtheguvnor Monufacture Effortless test data for MongoDB Tom Leach @tomtheguvnor | github.com/tleach
Transcript
Page 1: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

MonufactureEffortless test data for MongoDB

Tom Leach @tomtheguvnor | github.com/tleach

Page 2: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

MonufactureThe Spookiest Way To Create Test Data for MongoDB

Tom Leach @tomtheguvnor

Page 3: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

A little about me…

Page 4: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

A little about GameChanger…

Page 5: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

gc.com/careers

Page 6: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

GameChanger & MongoDB• Migrated to MongoDB 1.2 in 2009

• 12 TB of data (including 1,714,971,688 plays)

• Split across 10 shards

• 35 nodes in total

• Recently migrated all of this from EC2 Classic to VPC (5 mins downtime)

Page 7: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

“Testing MongoDB-dependent code”

• Unit tests (“classicist” not “mockist”)

• Integration tests

• Functional tests

• System tests

Page 8: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Why is testing this important?• MongoDB trades off many of the consistency guarantees provided by a traditional

RDBMS in favor of availability

• The onus is on the application developer to implement:

• Validation, Defaults, Sequences

• Concurrency handling

• Denormalization

• Referential integrity

• These are not simple problems to solve

Page 9: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Why is Mongo test data hard?

• Documents have arbitrarily complex nested structures

• Understanding what a valid document looks like is not obvious

• The DB does not really help us out

Page 10: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Typical approaches(we tried all of these)

Page 11: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Option 1: Static, “real-looking” database• Can run either manual or (scary) automated tests

• “Easy” to get started (clone production)

• Data is inventory which requires maintenance

• Non-deterministic

• Failures tend to have indirect causality and are time-consuming to diagnose

• Portability is hard

Page 12: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Option 2: Fixtures• Deterministic

• Brittle, non-obvious inter-test dependencies

• Static and painful to override

• Time consuming to maintain (inventory)

• Tend to bloat and slow tests

Page 13: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Option 3: Generate test data in tests

• Deterministic

• Localized causality*

• Boilerplate (especially in Mongo) obfuscates intent

• Expensive to create and maintain (schema changes)

• Overhead dis-incentivizes developers from writing tests

Page 14: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

What were we solving for?• Simple, readable, maintainable, concise tests

• Good coverage

• Tests are fast to write

• Developers who want to write tests because they are a help not a hindrance

• A cultural shift that scales

Page 15: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Team

Player

User

0..*

0..*

0..*

0..*

0..*

1

follows

family of

rosters

Page 16: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

What does a good test data API look like?

def test_add_player(self): team = create('team') add_player(team, 'Madison', 'Bumgarner') self.assertIn( {'first_name': 'Madison', 'last_name': 'Bumgarner'} db.team.find_one(team['_id'])['players'])

Page 17: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Introducing Monufacture

Page 18: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Mongopymongo

business logic modelling layer

tests monufacture

front end / HTTP API /

worker

Page 19: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

with factory('team', db.team): fragment('player', { 'first_name': text(), 'last_name': text(), 'number': sequence() }) default({ 'name': text(spaces=True), 'zip_code': 10007, 'players': list_of(

embed(‘player’), 5)

})

from monufacture import create

def test_add_player(self): team = create('team') add_player(team, 'Madison', 'Bumgarner') self.assertIn( {'first_name': 'Madison', 'last_name': 'Bumgarner'} db.team.find_one(team['_id'])['players'])

Declare factories centrally Use factories in tests

Page 20: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

Demo

Page 21: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

monufacture introduced

Page 22: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

–Gabriel Khaselev, GameChanger Engineer, Millennial

“Dude, you gotta check out Monufacture, it’s so dope.”

Page 23: Monufacture: Effortless Test Data for MongoDB

@tomtheguvnor

github.com/gamechanger/monufacture

Send us: • Feedback • Issues • Pull Requests

Also check out Mongothon (github.com/gamechanger/mongothon) - our Mongo modeling library with built-in validation, field defaults and events


Recommended