We have a few unit tests that aren't waiting for spans to be written, but which should. For example, TestClientOperations intermittently fails due to missing spans. According to the test log, FindSpan was called before the span is written to datastore.
This patch replaces WriteSpans with a semaphore. The reasoning is that it is sometimes difficult to debug unit tets where the datastore is blocked sending to the WriteSpans debug channel because the test has become blocked or is exiting. Buffered channels could eliminate this problem, but for certain tests, the buffers would have to be extremely large. Using a semaphore eliminates this problem. Semaphores will also be more efficient when we start ingesting spans in batches (see
HTRACE-298) since we can increment the semaphore once rather than sending multiple spans on the WriteSpans channel. This is important for getting realistic benchmarks.