KEMBAR78
Testing sync engine | PDF
Testing Sync Engine
Testing (iOS) Sync Engine
Agenda
• Overall tests stats
• Our test strategies
• MockTransportSession
• Workflow
• Problems
• Future plans
Overall tests stats
• 3356 tests on OSX
Overall tests stats
• 3356 tests on OSX
• 3415 tests on iOS (+ apns tests)
Overall tests stats
• 3356 tests on OSX
• 3415 tests on iOS (+ apns tests)
• ~ 7.5 minutes to build and run all the tests on
one platform (build ~ 40s, tests ~ 7 min)
Overall tests stats
• 3356 tests on OSX
• 3415 tests on iOS (+ apns tests)
• ~ 7.5 minutes to build and run all the tests on
one platform (build ~ 40s, tests ~ 7 min)
Overall tests stats
• Unit tests ~ 80%
Overall tests stats
• Unit tests ~ 80%
• Integration tests ~ 20%
Overall tests stats
• Unit tests ~ 80%
• Integration tests ~ 20%
• Performance tests - 18
Overall tests stats
• Unit tests ~ 80%
• Integration tests ~ 20%
• Performance tests - 18
• Tests of tests
Overall tests stats
• Unit tests ~ 80%
• Integration tests ~ 20%
• Performance tests - 18
• Tests of tests
• Sorry, no UI tests
Overall tests stats
Our test strategies
What we DON’T do:
Our test strategies
What we DON’T do:
• test against http:// (real backend)
• test using http requests stubs (like
OHHTTPStubs)
Our test strategies
What we DON’T do:
• test against http:// (real backend)
• test using http requests stubs (like
OHHTTPStubs)
Why?
• Stubs are not that flexible.
Our test strategies
What we DON’T do:
• test against http:// (real backend)
• test using http requests stubs (like
OHHTTPStubs)
Why?
• Stubs are not that flexible.
• It’s still slow.
Our test strategies
What we really do:
• Test against fake backend
Our test strategies
What we really do:
• Test against fake backend
Advantages
• Fast
• Flexible
• Independent
• Testable
Our test strategies
What we really do:
• Test against fake backend
Advantages
• Fast
• Flexible
• Independent
• Testable
Disadvantages
• Need to write (and
test!) code
• Need to be in sync
with real backend
(can be improved)
Our test strategies
MockTransportSession
WTF is THAT?
MockTransportSession
WTF is THAT?
ZMTransportSession
ZMTransportSessi
onErrorCode
ZMBackgroundAc
tivity
ZMURLSessionCa
ncelTimer
ZMURLSessionSw
itch
ZMURLSession
ZMTransportCodec
ZMAccessToken
ZMUserAgent
ZMReachability
ZMTransportData
ZMTransportResp
onse
ZMTaskIdentifierM
ap
ZMExponentialBa
ckoff
ZMAccessTokenH
andler
ZMTransportRequ
estScheduler
ZMNetworkSocket
ZMDataBuffer
ZMWebSocketFra
me
ZMWebSocketHan
dshake
ZMWebSocket
ZMPushChannelC
onnection
ZMTransportPush
Channel
ZMStreamPairThre
ad
MockTransportSession
WTF is THAT?
ZMTransportSession
MockTransportSession
WTF is THAT?
ZMTransportSession - is a delegate of a delegate
of NSURLSession
MockTransportSession
WTF is THAT?
ZMTransportSession - is a delegate of a delegate
of NSURLSession
• Sends http requests to scheduler
MockTransportSession
WTF is THAT?
ZMTransportSession - is a delegate of a delegate
of NSURLSession
• Sends http requests to scheduler
• Handles authentication
MockTransportSession
WTF is THAT?
ZMTransportSession - is a delegate of a delegate
of NSURLSession
• Sends http requests to scheduler
• Handles authentication
• Opens/closes web socket connection
MockTransportSession
WTF is THAT?
MockTransportSession - is a mock of
ZMTransportSession
MockTransportSession
WTF is THAT?
MockTransportSession - is a mock of
ZMTransportSession
MockTransportSession - acts as a fake backend
MockTransportSession
WTF is THAT?
• Make fake requests
MockTransportSession
WTF is THAT?
• Make fake requests
• Records requests and responds to them
MockTransportSession
WTF is THAT?
• Make fake requests
• Records requests and responds to them
• Manages internal database
MockTransportSession
WTF is THAT?
• Make fake requests
• Records requests and responds to them
• Manages internal database
• Can simulate remote changes.
MockTransportSession
WTF is THAT?
• Make fake requests
• Records requests and responds to them
• Manages internal database
• Can simulate remote changes.
• Can send push channel (web socket) events
MockTransportSession
• Before each test we insert objects in internal
database (in memory)
MockTransportSession
• Before each test we insert objects in internal
database (in memory)
• Test code make request using MockTransportSession
MockTransportSession
• Before each test we insert objects in internal
database (in memory)
• Test code make request using MockTransportSession
• It records and process incoming request (filtering by
path and lots of ifs)
MockTransportSession
• Before each test we insert objects in internal
database (in memory)
• Test code make request using MockTransportSession
• It records and process incoming request (filtering by
path and lots of ifs)
• Performs some CRUD action on database
depending on request (add message, create
conversation, fetch conversation)
MockTransportSession
• Before each test we insert objects in internal
database (in memory)
• Test code make request using MockTransportSession
• It records and process incoming request (filtering by
path and lots of ifs)
• Performs some CRUD action on database
depending on request (add message, create
conversation, fetch conversation)
• Creates and sends response. Optionally can
delegate it to other object (i.e. test case).
MockTransportSession
Workflow
• Finished feature - run all the tests
Workflow
• Finished feature - run all the tests
• Create pull request
Workflow
• Finished feature - run all the tests
• Create pull request
• Review, merge
Workflow
• Finished feature - run all the tests
• Create pull request
• Review, merge
• Release script runs all tests locally
Workflow
• Finished feature - run all the tests
• Create pull request
• Review, merge
• Release script runs all tests locally
• Pushes to remote branches (master/develop)
Workflow
• Finished feature - run all the tests
• Create pull request
• Review, merge
• Release script runs all tests locally
• Pushes to remote branches (master/develop)
• Xcode bots make integration on each push to master/
develop
Workflow
• Finished feature - run all the tests
• Create pull request
• Review, merge
• Release script runs all tests locally
• Pushes to remote branches (master/develop)
• Xcode bots make integration on each push to master/
develop
• Each bot for each platform runs all the tests
Workflow
• Finished feature - run all the tests
• Create pull request
• Review, merge
• Release script runs all tests locally
• Pushes to remote branches (master/develop)
• Xcode bots make integration on each push to master/
develop
• Each bot for each platform runs all the tests
• Bots archive and upload binary to the cloud
Workflow
Problems
Solved:
• Tests isolation (mostly database state)
Problems
Solved:
• Tests isolation (mostly database state)
• Handling asynchronous code
Problems
Solved:
• Tests isolation (mostly database state)
• Handling asynchronous code
Not yet solved:
Problems
Solved:
• Tests isolation (mostly database state)
• Handling asynchronous code
Not yet solved:
• Reduce tests running time
U don’t like
me? =(
Problems
Solved:
• Tests isolation (mostly database state)
• Handling asynchronous code
Not yet solved:
• Reduce tests running time
• Sync with real backend
Problems
Solved:
• Tests isolation (mostly database state)
• Handling asynchronous code
Not yet solved:
• Reduce tests running time
• Sync with real backend
• Flaky tests
Problems
Future plans
• Split to smaller frameworks - to improve run time
Future plans
• Split to smaller frameworks - to improve run time
• Setup Buildasaur - to run tests on Github pull
requests
Future plans
• Split to smaller frameworks - to improve run time
• Setup Buildasaur - to run tests on Github pull
requests
• Record/replay tests for MockTransportSession -
to keep it in sync
Future plans
That’s it!

Testing sync engine