Project-OSRM/osrm-backend — pull request #1231 by emiltin (2014-10-17 13:29:24+00:00)
Title: smarter caching of test files

This OR makes cucumber smarter about caching files produces at each stage of the processing chain. For exammple, if you change only osrm-routed, the data files will not have be extracted and prepared again, but can instead be reused from the cache, which mean they are very fast to run (22s instead of several minutes on my linux box.)

Similarly, if you modify only osrm-prepare, extraction will not have to be repeated during testing.

Unfortuntely, the fingerprinting mechanism currently cause all binaries be rebuild when certain files are modified, which invalidates all cache files, see #1229.

Example flow below.

Sha1 of initial build binaries:
```
~/code/osrm-backend$ (smartcache) sha1sum build/osrm-extract build/osrm-prepare build/osrm-routed
0e02023e72cfef7770dd7c9ffdf73066d65443d2 build/osrm-extract
ec87650e168735314b028a6c392e567f4c4cafe5 build/osrm-prepare
b71b0f2713f4d53ccdaae619ada0d4f05b187bc8 build/osrm-routed
```

Change some code in Server/RequestHandler.cpp;
```
~/code/osrm-backend$ (smartcache *) git diff
diff --git a/Server/RequestHandler.cpp b/Server/RequestHandler.cpp
index b358d8d..fd1958d 100644
--- a/Server/RequestHandler.cpp
+++ b/Server/RequestHandler.cpp
@@ -133,7 +133,7 @@ void RequestHandler::handle_request(const http::Request &req, http::Reply &reply
catch (const std::exception &e)
{
reply = http::Reply::StockReply(http::Reply::internalServerError);
- SimpleLogger().Write(logWARNING) << "[server error] code: " << e.what()
+ SimpleLogger().Write(logWARNING) << "[server error] code k: " << e.what()
<< ", uri: " << req.uri;
return;
}
```

Rebuild:
```
~/code/osrm-backend$ (smartcache *) rake
[ 2%] Built target COORDINATE
[ 5%] Configuring FingerPrint.cpp
[ 5%] Built target FingerPrintConfigure
[ 7%] Configuring FingerPrint.cpp
[ 10%] Building CXX object CMakeFiles/FINGERPRINT.dir/Util/FingerPrint.cpp.o
[ 10%] Built target FINGERPRINT
[ 12%] Built target GITDESCRIPTION
[ 17%] Built target IMPORT
[ 20%] Built target LOGGER
[ 23%] Configuring FingerPrint.cpp
[ 25%] Building CXX object CMakeFiles/OSRM.dir/Util/FingerPrint.cpp.o
Linking CXX static library libOSRM.a
[ 48%] Built target OSRM
Linking CXX executable osrm-datastore
[ 51%] Built target osrm-datastore
Linking CXX executable osrm-extract
[ 71%] Built target osrm-extract
Linking CXX executable osrm-prepare
[ 89%] Built target osrm-prepare
Scanning dependencies of target osrm-routed
[ 92%] Building CXX object CMakeFiles/osrm-routed.dir/Server/RequestHandler.cpp.o
Linking CXX executable osrm-routed
[100%] Built target osrm-routed
```

After rebuilding, the sha1 of osrm-routed changed:
```
~/code/osrm-backend$ (smartcache *) sha1sum build/osrm-extract build/osrm-prepare build/osrm-routed
0e02023e72cfef7770dd7c9ffdf73066d65443d2 build/osrm-extract
ec87650e168735314b028a6c392e567f4c4cafe5 build/osrm-prepare
58b82ebaabda88846bff41e8f0df8629316e364f build/osrm-routed
```

Because osrm-extact and osrm-prepare didn't change, all cached test files can be reused, which mean rerunning test is still very fast:
```
~/code/osrm-backend$ (smartcache *) cuke
...
354 scenarios (354 passed)
1471 steps (1471 passed)
0m23.048s # still fast
```