Skip to content

Commit

Permalink
more stable testing strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
richardstartin committed Jun 30, 2020
1 parent 25551ca commit f39e025
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,12 @@ class DDAgentWriterTest extends DDSpecification {

def "test backed up buffer"() {
setup:
System.gc() // seems to reduce false negatives
def minimalTrace = createMinimalTrace()
AtomicInteger backedUp = new AtomicInteger(0)
def serializer = Spy(new MsgPackStatefulSerializer())
def monitor = Mock(Monitor)
def api = Mock(DDAgentApi)
def latch = new CountDownLatch(1)
def arbitrator = Executors.newSingleThreadScheduledExecutor()
def dispatcher = new DispatchingDisruptor(2,
DDAgentWriter.toEventFactory(serializer),
Expand All @@ -694,27 +694,24 @@ class DDAgentWriterTest extends DDSpecification {
when:
api.sendSerializedTraces(_) >> {
// wait to be unblocked, by which time the test aims to have created a backlog
latch.await()
Thread.sleep(500)
DDAgentApi.Response.success(200)
}
// if the code below can't run within a second,
// the test will fail, but this behaviour is hard to provoke with latches
monitor.onBackedUpTraceBuffer() >> { backedUp.incrementAndGet() }
long txnId1 = dispatcher.beginTransaction()
serializer.reset(dispatcher.getTraceBuffer(txnId1))
serializer.serialize(minimalTrace)
dispatcher.commit(txnId1)
arbitrator.schedule({
latch.countDown()
}, 1000, TimeUnit.MILLISECONDS)
// if the code below can't run within a second (when the latch is counted down),
// the test will fail, but this behaviour is hard to provoke with latches
long txnId2 = dispatcher.beginTransaction()
serializer.reset(dispatcher.getTraceBuffer(txnId2))
serializer.serialize(minimalTrace)
dispatcher.commit(txnId2)
long txnId3 = dispatcher.beginTransaction()

then:
backedUp.get() == 1 // reported the congestion
backedUp.get() >= 1 // reported the congestion
txnId3 == 2 // made progress eventually

cleanup:
Expand Down

0 comments on commit f39e025

Please sign in to comment.