Browse Source

Merge pull request #15484 from smatvienko-tb/fix/flaky-DeviceProfileControllerTest-testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaRequestIdDateType

Fix flaky DeviceProfileControllerTest.testSaveProtoDeviceProfileWithInvalidRpcRequestSchemaRequestIdDateType
pull/15509/head
Viacheslav Klimov 1 month ago
committed by GitHub
parent
commit
4932522aa4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java

18
application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java

@ -54,11 +54,13 @@ import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.dao.device.DeviceProfileDao;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.service.DaoSqlTest;
import org.awaitility.Awaitility;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
@ -1028,11 +1030,17 @@ public class DeviceProfileControllerTest extends AbstractControllerTest {
MqttDeviceProfileTransportConfiguration mqttDeviceProfileTransportConfiguration = this.createMqttDeviceProfileTransportConfiguration(protoTransportPayloadConfiguration, false);
DeviceProfile deviceProfile = this.createDeviceProfile("Device Profile", mqttDeviceProfileTransportConfiguration);
Mockito.reset(tbClusterService, auditLogService);
doPost("/api/deviceProfile", deviceProfile)
.andExpect(status().isBadRequest())
.andExpect(statusReason(containsString(errorMsg)));
// The request may hit a transient TenantNotFoundException right after the @Before tenant creation
// if the tenant profile cache is not yet warmed up for the newly created tenant. Retry until the
// request returns the expected 400 Bad Request for the invalid schema. Mockito.reset is inside the
// retry loop so the subsequent verify* assertions see only the invocations from the last attempt.
Awaitility.await().atMost(10, TimeUnit.SECONDS).pollInterval(500, TimeUnit.MILLISECONDS)
.ignoreExceptions().untilAsserted(() -> {
Mockito.reset(tbClusterService, auditLogService);
doPost("/api/deviceProfile", deviceProfile)
.andExpect(status().isBadRequest())
.andExpect(statusReason(containsString(errorMsg)));
});
testNotifyEntityEqualsOneTimeServiceNeverError(deviceProfile, savedTenant.getId(),
tenantAdmin.getId(), tenantAdmin.getEmail(), ActionType.ADDED, new DataValidationException(errorMsg));

Loading…
Cancel
Save