Skip to content

Commit

Permalink
Fix flaky CacheProviderTest (#8684)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Jun 11, 2023
1 parent 63a698b commit 8cfacd5
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package io.opentelemetry.javaagent.tooling

import io.opentelemetry.javaagent.tooling.muzzle.AgentCachingPoolStrategy
import net.bytebuddy.description.type.TypeDescription
import net.bytebuddy.dynamic.ClassFileLocator
import net.bytebuddy.pool.TypePool
import spock.lang.Specification

Expand Down Expand Up @@ -39,6 +38,8 @@ class CacheProviderTest extends Specification {
expect:
key1.hashCode() == key2.hashCode()
key1.equals(key2)
// ensures that loader isn't collected
loader != null
}

def "key different ref equivalence"() {
Expand All @@ -56,6 +57,8 @@ class CacheProviderTest extends Specification {

key1.hashCode() == key2.hashCode()
key1.equals(key2)
// ensures that loader isn't collected
loader != null
}

def "key mismatch -- same loader - diff name"() {
Expand All @@ -70,6 +73,8 @@ class CacheProviderTest extends Specification {
// not strictly guaranteed -- but important for performance
fooKey.hashCode() != barKey.hashCode()
!fooKey.equals(barKey)
// ensures that loader isn't collected
loader != null
}

def "key mismatch -- same name - diff loader"() {
Expand All @@ -89,6 +94,9 @@ class CacheProviderTest extends Specification {
// not strictly guaranteed -- but important for performance
fooKey1.hashCode() != fooKey2.hashCode()
!fooKey1.equals(fooKey2)
// ensures that loader isn't collected
loader1 != null
loader2 != null
}

def "test basic caching"() {
Expand All @@ -105,6 +113,8 @@ class CacheProviderTest extends Specification {
then:
// not strictly guaranteed, but fine for this test
cacheProvider.find("foo") != null
// ensures that loader isn't collected
loader != null
}

def "test loader equivalence"() {
Expand All @@ -125,6 +135,9 @@ class CacheProviderTest extends Specification {
cacheProvider1B.find("foo") != null

cacheProvider1A.find("foo").is(cacheProvider1B.find("foo"))

// ensures that loader isn't collected
loader1 != null
}

def "test loader separation"() {
Expand All @@ -147,26 +160,17 @@ class CacheProviderTest extends Specification {
cacheProvider2.find("foo") != null

!cacheProvider1.find("foo").is(cacheProvider2.find("foo"))

// ensures that loader isn't collected
loader1 != null
loader2 != null
}

static newVoid() {
return new TypePool.Resolution.Simple(TypeDescription.VOID)
return new TypePool.Resolution.Simple(TypeDescription.ForLoadedType.of(void.class))
}

static newClassLoader() {
return new URLClassLoader([] as URL[], (ClassLoader) null)
}

static newLocator() {
return new ClassFileLocator() {
@Override
ClassFileLocator.Resolution locate(String name) throws IOException {
return null
}

@Override
void close() throws IOException {
}
}
}
}

0 comments on commit 8cfacd5

Please sign in to comment.