More fixes to Lettuce tests
Lettuce intrumentatio is implemented in a way that after operation has been performed `span` is not closed syncronously - in fact this happens on separate thread. This means `spans` for even syncronous operations may be closed on opposite order. This means that writing tests that pefrom two operations and expect two traces is slightly more complicated. In many places we can just avoid doing that by preparing necessary data in `setup`. This fixes some of the false negatives in tests.
This commit is contained in:
parent
770f77a7ff
commit
1fbb33d182
|
@ -72,7 +72,10 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
asyncCommands = connection.async()
|
asyncCommands = connection.async()
|
||||||
syncCommands = connection.sync()
|
syncCommands = connection.sync()
|
||||||
|
|
||||||
TEST_WRITER.waitForTraces(1)
|
syncCommands.set("TESTKEY", "TESTVAL")
|
||||||
|
|
||||||
|
// 1 set + 1 connect trace
|
||||||
|
TEST_WRITER.waitForTraces(2)
|
||||||
TEST_WRITER.clear()
|
TEST_WRITER.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +165,7 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "set command using Future get with timeout"() {
|
def "set command using Future get with timeout"() {
|
||||||
setup:
|
setup:
|
||||||
RedisFuture<String> redisFuture = asyncCommands.set("TESTKEY", "TESTVAL")
|
RedisFuture<String> redisFuture = asyncCommands.set("TESTSETKEY", "TESTSETVAL")
|
||||||
String res = redisFuture.get(3, TimeUnit.SECONDS)
|
String res = redisFuture.get(3, TimeUnit.SECONDS)
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
|
@ -190,8 +193,6 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "get command chained with thenAccept"() {
|
def "get command chained with thenAccept"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.set("TESTKEY", "TESTVAL")
|
|
||||||
|
|
||||||
def conds = new AsyncConditions()
|
def conds = new AsyncConditions()
|
||||||
Consumer<String> consumer = new Consumer<String>() {
|
Consumer<String> consumer = new Consumer<String>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -208,25 +209,8 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
then:
|
then:
|
||||||
conds.await()
|
conds.await()
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "SET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
@ -301,14 +285,12 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "command with no arguments using a biconsumer"() {
|
def "command with no arguments using a biconsumer"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.set("TESTKEY", "TESTVAL")
|
|
||||||
|
|
||||||
def conds = new AsyncConditions()
|
def conds = new AsyncConditions()
|
||||||
BiConsumer<String, Throwable> biConsumer = new BiConsumer<String, Throwable>() {
|
BiConsumer<String, Throwable> biConsumer = new BiConsumer<String, Throwable>() {
|
||||||
@Override
|
@Override
|
||||||
void accept(String keyRetrieved, Throwable throwable) {
|
void accept(String keyRetrieved, Throwable throwable) {
|
||||||
conds.evaluate{
|
conds.evaluate{
|
||||||
assert keyRetrieved == "TESTKEY"
|
assert keyRetrieved != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,25 +301,8 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
then:
|
then:
|
||||||
conds.await()
|
conds.await()
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "SET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
@ -362,14 +327,15 @@ class LettuceAsyncClientTest extends AgentTestRunner {
|
||||||
def conds = new AsyncConditions()
|
def conds = new AsyncConditions()
|
||||||
|
|
||||||
when:
|
when:
|
||||||
RedisFuture<String> hmsetFuture = asyncCommands.hmset("user", testHashMap)
|
RedisFuture<String> hmsetFuture = asyncCommands.hmset("TESTHM", testHashMap)
|
||||||
hmsetFuture.thenApplyAsync(new Function<String, Object>() {
|
hmsetFuture.thenApplyAsync(new Function<String, Object>() {
|
||||||
@Override
|
@Override
|
||||||
Object apply(String setResult) {
|
Object apply(String setResult) {
|
||||||
|
TEST_WRITER.waitForTraces(1) // Wait for 'hmset' trace to get written
|
||||||
conds.evaluate {
|
conds.evaluate {
|
||||||
assert setResult == "OK"
|
assert setResult == "OK"
|
||||||
}
|
}
|
||||||
RedisFuture<Map<String, String>> hmGetAllFuture = asyncCommands.hgetall("user")
|
RedisFuture<Map<String, String>> hmGetAllFuture = asyncCommands.hgetall("TESTHM")
|
||||||
hmGetAllFuture.exceptionally(new Function<Throwable, Map<String, String>>() {
|
hmGetAllFuture.exceptionally(new Function<Throwable, Map<String, String>>() {
|
||||||
@Override
|
@Override
|
||||||
Map<String, String> apply(Throwable throwable) {
|
Map<String, String> apply(Throwable throwable) {
|
||||||
|
|
|
@ -49,7 +49,10 @@ class LettuceReactiveClientTest extends AgentTestRunner {
|
||||||
reactiveCommands = connection.reactive()
|
reactiveCommands = connection.reactive()
|
||||||
syncCommands = connection.sync()
|
syncCommands = connection.sync()
|
||||||
|
|
||||||
TEST_WRITER.waitForTraces(1)
|
syncCommands.set("TESTKEY", "TESTVAL")
|
||||||
|
|
||||||
|
// 1 set + 1 connect trace
|
||||||
|
TEST_WRITER.waitForTraces(2)
|
||||||
TEST_WRITER.clear()
|
TEST_WRITER.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +74,7 @@ class LettuceReactiveClientTest extends AgentTestRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
when:
|
when:
|
||||||
reactiveCommands.set("TESTKEY", "TESTVAL").subscribe(consumer)
|
reactiveCommands.set("TESTSETKEY", "TESTSETVAL").subscribe(consumer)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
conds.await()
|
conds.await()
|
||||||
|
@ -98,7 +101,6 @@ class LettuceReactiveClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "get command with lambda function"() {
|
def "get command with lambda function"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.set("TESTKEY", "TESTVAL")
|
|
||||||
def conds = new AsyncConditions()
|
def conds = new AsyncConditions()
|
||||||
|
|
||||||
when:
|
when:
|
||||||
|
@ -106,25 +108,8 @@ class LettuceReactiveClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
then:
|
then:
|
||||||
conds.await()
|
conds.await()
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "SET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
@ -184,7 +169,6 @@ class LettuceReactiveClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "command with no arguments"() {
|
def "command with no arguments"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.set("TESTKEY", "TESTVAL")
|
|
||||||
def conds = new AsyncConditions()
|
def conds = new AsyncConditions()
|
||||||
|
|
||||||
when:
|
when:
|
||||||
|
@ -196,25 +180,8 @@ class LettuceReactiveClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
then:
|
then:
|
||||||
conds.await()
|
conds.await()
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "SET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
|
|
@ -53,7 +53,12 @@ class LettuceSyncClientTest extends AgentTestRunner {
|
||||||
redisServer.start()
|
redisServer.start()
|
||||||
connection = redisClient.connect()
|
connection = redisClient.connect()
|
||||||
syncCommands = connection.sync()
|
syncCommands = connection.sync()
|
||||||
TEST_WRITER.waitForTraces(1)
|
|
||||||
|
syncCommands.set("TESTKEY", "TESTVAL")
|
||||||
|
syncCommands.hmset("TESTHM", testHashMap)
|
||||||
|
|
||||||
|
// 2 sets + 1 connect trace
|
||||||
|
TEST_WRITER.waitForTraces(3)
|
||||||
TEST_WRITER.clear()
|
TEST_WRITER.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +142,7 @@ class LettuceSyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "set command"() {
|
def "set command"() {
|
||||||
setup:
|
setup:
|
||||||
String res = syncCommands.set("TESTKEY", "TESTVAL")
|
String res = syncCommands.set("TESTSETKEY", "TESTSETVAL")
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
res == "OK"
|
res == "OK"
|
||||||
|
@ -164,30 +169,12 @@ class LettuceSyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "get command"() {
|
def "get command"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.set("TESTKEY", "TESTVAL")
|
|
||||||
String res = syncCommands.get("TESTKEY")
|
String res = syncCommands.get("TESTKEY")
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
res == "TESTVAL"
|
res == "TESTVAL"
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "SET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
@ -236,30 +223,12 @@ class LettuceSyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "command with no arguments"() {
|
def "command with no arguments"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.set("TESTKEY", "TESTVAL")
|
|
||||||
def keyRetrieved = syncCommands.randomkey()
|
def keyRetrieved = syncCommands.randomkey()
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
keyRetrieved == "TESTKEY"
|
keyRetrieved != null
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "SET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
@ -335,30 +304,12 @@ class LettuceSyncClientTest extends AgentTestRunner {
|
||||||
|
|
||||||
def "hash getall command"() {
|
def "hash getall command"() {
|
||||||
setup:
|
setup:
|
||||||
syncCommands.hmset("user", testHashMap)
|
Map<String, String> res = syncCommands.hgetall("TESTHM")
|
||||||
Map<String, String> res = syncCommands.hgetall("user")
|
|
||||||
|
|
||||||
expect:
|
expect:
|
||||||
res == testHashMap
|
res == testHashMap
|
||||||
assertTraces(TEST_WRITER, 2) {
|
assertTraces(TEST_WRITER, 1) {
|
||||||
trace(0, 1) {
|
trace(0, 1) {
|
||||||
span(0) {
|
|
||||||
serviceName "redis"
|
|
||||||
operationName "redis.query"
|
|
||||||
spanType "redis"
|
|
||||||
resourceName "HMSET"
|
|
||||||
errored false
|
|
||||||
|
|
||||||
tags {
|
|
||||||
defaultTags()
|
|
||||||
"component" "redis-client"
|
|
||||||
"db.type" "redis"
|
|
||||||
"span.kind" "client"
|
|
||||||
"span.type" "redis"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
trace(1, 1) {
|
|
||||||
span(0) {
|
span(0) {
|
||||||
serviceName "redis"
|
serviceName "redis"
|
||||||
operationName "redis.query"
|
operationName "redis.query"
|
||||||
|
|
Loading…
Reference in New Issue