Skip to content

Commit

Permalink
Add a few logs to troubleshoot flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-alvarez-alvarez committed Jun 25, 2024
1 parent 174ea28 commit 59a9244
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public Range[] getRanges() {
public void setRanges(@Nonnull final Range[] ranges) {
this.ranges = ranges;
}

@Override
public String toString() {
final Object referent = get();
return "[hash: "
+ positiveHashCode
+ ", gen: "
+ generation
+ "] "
+ (referent == null ? "GCed" : referent)
+ " ("
+ (ranges == null ? 0 : ranges.length)
+ " ranges)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ class ObjectGen {

final int capacity
final Map<Integer, List<Object>> pool
final Closure<Object> factory

ObjectGen(int capacity) {
ObjectGen(int capacity, Closure<Object> factory = { new Object() }) {
assert (capacity & (capacity - 1)) == 0, 'capacity must be a power of 2'
this.capacity = capacity
this.pool = new HashMap<>(capacity)
for (int i = 0; i < capacity; i++) {
this.pool.put(i, new ArrayList<Object>())
}
this.factory = factory
}

def genBuckets(int nBuckets, int nObjects) {
Expand Down Expand Up @@ -57,7 +59,7 @@ class ObjectGen {
def genObjects(int nObjects, Closure<Boolean> isValid) {
def res = new ArrayList(nObjects)
while (res.size() < nObjects) {
def obj = new Object()
def obj = factory.call()
int bucket = getIndex(obj)
if (isValid.call(bucket)) {
res.add(obj)
Expand All @@ -69,7 +71,7 @@ class ObjectGen {
}

def genObject() {
def obj = new Object()
def obj = factory.call()
int bucket = getIndex(obj)
pool.get(bucket).add(obj)
return bucket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import datadog.trace.util.AgentTaskScheduler
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicInteger

class TaintedMapTest extends DDSpecification {

Expand Down Expand Up @@ -94,7 +95,8 @@ class TaintedMapTest extends DDSpecification {

int iters = 16
int nObjectsPerIter = flatModeThreshold - 1
def gen = new ObjectGen(capacity)
final atomic = new AtomicInteger()
def gen = new ObjectGen(capacity, { "object_${atomic.incrementAndGet()}"} )
def objectBuffer = new CircularBuffer<Object>(iters)

when:
Expand All @@ -119,7 +121,7 @@ class TaintedMapTest extends DDSpecification {
}

then:
map.size() == iters
assert map.size() == iters: map.toList()
map.count() == iters
final entries = map.toList()
entries.findAll { it.get() != null }.size() == iters
Expand Down

0 comments on commit 59a9244

Please sign in to comment.