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 @Data
public class CoapTestCallback implements CoapHandler { public class CoapTestCallback implements CoapHandler {
protected Integer observe; protected volatile Integer observe;
protected byte[] payloadBytes; protected volatile byte[] payloadBytes;
protected CoAP.ResponseCode responseCode; protected volatile CoAP.ResponseCode responseCode;
public Integer getObserve() { public Integer getObserve() {
return observe; return observe;

View File

@ -56,7 +56,7 @@
<cassandra-all.version>3.11.14</cassandra-all.version> <cassandra-all.version>3.11.14</cassandra-all.version>
<guava.version>31.1-jre</guava.version> <guava.version>31.1-jre</guava.version>
<caffeine.version>2.6.1</caffeine.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-codec.version>1.15</commons-codec.version>
<commons-io.version>2.11.0</commons-io.version> <commons-io.version>2.11.0</commons-io.version>
<commons-logging.version>1.2</commons-logging.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.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -41,6 +40,7 @@ import org.thingsboard.server.common.msg.TbMsgMetaData;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.assertThatThrownBy;
@ -169,21 +169,20 @@ public class TbHttpClientTest {
capturedData.capture() capturedData.capture()
)).thenReturn(successMsg); )).thenReturn(successMsg);
httpClient.processMessage(ctx, msg, CountDownLatch latch = new CountDownLatch(1);
m -> ctx.tellSuccess(msg),
ctx::tellFailure);
Awaitility.await() httpClient.processMessage(ctx, msg,
.atMost(30, TimeUnit.SECONDS) m -> {
.until(() -> { ctx.tellSuccess(msg);
try { latch.countDown();
verify(ctx, times(1)).tellSuccess(any()); },
return true; (m, t) -> {
} catch (Exception e) { ctx.tellFailure(m, t);
return false; latch.countDown();
}
}); });
latch.await(5, TimeUnit.SECONDS);
verify(ctx, times(1)).tellSuccess(any()); verify(ctx, times(1)).tellSuccess(any());
verify(ctx, times(0)).tellFailure(any(), any()); verify(ctx, times(0)).tellFailure(any(), any());
Assertions.assertEquals(successResponseBody, capturedData.getValue()); Assertions.assertEquals(successResponseBody, capturedData.getValue());