test failed, then

36
Test Failed, Then... Optimizing communication between people Toru Furukawa @torufurukawa

Upload: toru-furukawa

Post on 25-Jun-2015

1.407 views

Category:

Technology


0 download

DESCRIPTION

Pycon APAC presentation on optimizing inter-component communication and inter-engineer communication.

TRANSCRIPT

Page 1: Test Failed, Then

Test Failed, Then...Optimizing communication between people

Toru Furukawa"@torufurukawa"

Page 2: Test Failed, Then

Agenda •  Introduction

Web app syncing with live TV show"•  Loose coupling"•  Testable components"•  Efficient communication"

Page 3: Test Failed, Then
Page 4: Test Failed, Then

Agile App Development on Concrete Backend Services

HTML App"

App Server

Backend Service(s)"

Project  dependent

Common

Page 5: Test Failed, Then

Because... •  Requirements keep changing"•  Not only Web, but also TV"•  Not only TV, but also Web"•  Spiky access traffic"•  Common fundamental features"

▼"•  Easy to change application"•  Well tested platform"

Page 6: Test Failed, Then

Ended up with…

HTML App"

App Server

Counter" Messenger"

Page 7: Test Failed, Then

High Communication Cost

"Communication overheads increase as the number of people increases." F. Brooks"

Page 8: Test Failed, Then

Minimal and Effective Communication

Page 9: Test Failed, Then

Optimize Communication •  Between Components"•  Between People

Page 10: Test Failed, Then
Page 11: Test Failed, Then

How to Simplify Dependency?

HTML App"

App Server Counter" Messenger"

Page 12: Test Failed, Then

PHP •  IMPORTANT: PHP is fine"•  Cannot be combined with Python

component in language layer easily

Page 13: Test Failed, Then

Loose Coupling "Write small services that speak HTTP and bridge them together with another application.""

Armin Ronacher (@mitsuhiko)" http://lucumr.pocoo.org/2010/12/24/common-mistakes-as-web-developer/

HTTP

Page 14: Test Failed, Then

Loose Coupling

HTML App"(JavaScript)

App Server"(whatever)

Counter"(Python)

Messenger"(Node.js)

HTTP

HTTP

Page 15: Test Failed, Then

Assign Engineer for Component

HTML App"(JavaScript)

App Server"(whatever)

Counter"(Python)

Messenger"(Node.js)

HTTP

Page 16: Test Failed, Then

Communication Paths

Page 17: Test Failed, Then

2 Projects Running

Page 18: Test Failed, Then

Wrap Engineers' Communication

•  New layers to simplify inter-component communication"

•  Assign new roles to simplify inter-people communication

Page 19: Test Failed, Then

HTML App"(JavaScript)

App Server"(whatever)

Counter"(Python)

Messenger"(Node.js)

Server/Server Communication"(Python)

Client/Server Communication

Page 20: Test Failed, Then
Page 21: Test Failed, Then
Page 22: Test Failed, Then

If a servicewise feature does not work, how to identify the cause?"•  Ask developer to check logs?"•  Ask developer to check DB?"

▼"Make component diagnosable"

Instrument Components

Page 23: Test Failed, Then

Log with fluentd

App Server"(whatever)

Counter"(Python)

Messenger"(Node.js)

fluentd

Mongo  DB Web App

Page 24: Test Failed, Then

Define CRUD APIs •  Make DB accessible from test and admin

•  REST /objects/:id"•  /get_objects

/get_object, /set_object, /delete_object"▼"

•  Diagnose 1-layer deeper from outside"

Page 25: Test Failed, Then

"requests" package for Web API Access

>>>  r  =  requests.get(url,  auth=(...),  ...)  >>>  r  =  requests.post(url,  data={...},  ...)  >>>  r.status_code  200  >>>  r.content  u'{"foo":"bar","x":true}'  >>>  r.json()  {u'foo':  u'bar',  'x':  True}  

Page 26: Test Failed, Then

Library for Productivity •  Use testing libraries to increase

productivity i.e. how many test you write per hour"

•  setup and teardown"– unittest"– nose"– py.test"–  testfixtures"– etc.

Page 27: Test Failed, Then
Page 28: Test Failed, Then

Translate Test Report Traceback  (most  recent  call  last):      File  "mytest.py",  line  7,  in  test          assert  result  ==  expected  AssertionError  

▼"•  How do YOU determine what is wrong?"•  How do you tell OTHERS what is wrong?"

▼"•  Need better way to communicate

Page 29: Test Failed, Then

Library for Readability class  MyTest(unittest.TestCase):          def  test(self):                  expected  =  {...}                  result  =  {...}                  self.assertEqual(x,  y)  

""

Page 30: Test Failed, Then

Traceback  (most  recent  call  last):      File  "mytest.py",  line  7,  in  test          self.assertEqual(x,  y)  AssertionError:  {'items':  ['spam',  'spam'],  'foo':  'bar'}  !=  {'items':  ['spam',  'ham'],  'foo':  'bar'}  -­‐  {'foo':  'bar',  'items':  ['spam',  'spam']}  ?                                                                      ^^    +  {'foo':  'bar',  'items':  ['spam',  'ham']}  ?                                                                      ^

Page 31: Test Failed, Then

Python vs HTTP

Python

HTTP

Test Fast

Loosely Couple

Develop Fast

Page 32: Test Failed, Then

If I stick to Python too much,my communication is

tightly coupled

Page 33: Test Failed, Then

Convert requests function to curl >>>  import  curledrequests  as  requests  >>>  requests.debug  =  True  >>>  r  =  requests.get(  ...      'http://www.google.com/',  ...      params={'q':'python'})  ...  $  curl  “http://www.google.com/?q=python”  -­‐w  '\n%{http_code}\n'  <!doctype  html><html  itemscope=""  itemtype="http://schema.org/WebPage"><head><me  ...  200  

h5p://goo.gl/hO579O  

Page 34: Test Failed, Then
Page 35: Test Failed, Then

Loosely Couple Components and Engineers

Page 36: Test Failed, Then

Share Your Practice

@torufurukawa or grab me"