Merge pull request #9817 from YevhenBondarenko/fix/tests

fixed flaky tests
This commit is contained in:
Andrew Shvayka 2023-12-13 14:06:48 +02:00 committed by GitHub
commit 39a5944ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 17 deletions

View File

@ -25,9 +25,9 @@ import org.eclipse.californium.core.coap.CoAP;
@Data
public class CoapTestCallback implements CoapHandler {
protected Integer observe;
protected byte[] payloadBytes;
protected CoAP.ResponseCode responseCode;
protected volatile Integer observe;
protected volatile byte[] payloadBytes;
protected volatile CoAP.ResponseCode responseCode;
public Integer getObserve() {
return observe;

View File

@ -56,7 +56,7 @@
<cassandra-all.version>3.11.14</cassandra-all.version>
<guava.version>31.1-jre</guava.version>
<caffeine.version>2.6.1</caffeine.version>
<commons-lang3.version>3.4</commons-lang3.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-codec.version>1.15</commons-codec.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-logging.version>1.2</commons-logging.version>

View File

@ -18,7 +18,6 @@ package org.thingsboard.rule.engine.rest;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
@ -41,6 +40,7 @@ import org.thingsboard.server.common.msg.TbMsgMetaData;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@ -169,21 +169,20 @@ public class TbHttpClientTest {
capturedData.capture()
)).thenReturn(successMsg);
httpClient.processMessage(ctx, msg,
m -> ctx.tellSuccess(msg),
ctx::tellFailure);
CountDownLatch latch = new CountDownLatch(1);
Awaitility.await()
.atMost(30, TimeUnit.SECONDS)
.until(() -> {
try {
verify(ctx, times(1)).tellSuccess(any());
return true;
} catch (Exception e) {
return false;
}
httpClient.processMessage(ctx, msg,
m -> {
ctx.tellSuccess(msg);
latch.countDown();
},
(m, t) -> {
ctx.tellFailure(m, t);
latch.countDown();
});
latch.await(5, TimeUnit.SECONDS);
verify(ctx, times(1)).tellSuccess(any());
verify(ctx, times(0)).tellFailure(any(), any());
Assertions.assertEquals(successResponseBody, capturedData.getValue());