Skip to content

Commit 4e91705

Browse files
committed
Fix logic for milliseconds
1 parent e1d420f commit 4e91705

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,12 @@ public static Instant getStepStartTime(@Nullable String scenarioUniqueId, Map<St
564564
stepStartTimeMap.put(scenarioUniqueId, currentStepStartTime);
565565
return currentStepStartTime;
566566
}
567-
if (lastStepStartTime.compareTo(currentStepStartTime) >= 0) {
568-
if (useMicroseconds) {
567+
if (useMicroseconds) {
568+
if (lastStepStartTime.compareTo(currentStepStartTime) >= 0) {
569569
currentStepStartTime = lastStepStartTime.plus(1, ChronoUnit.MICROS);
570-
} else {
570+
}
571+
} else {
572+
if (lastStepStartTime.truncatedTo(ChronoUnit.MILLIS).compareTo(currentStepStartTime.truncatedTo(ChronoUnit.MILLIS)) >= 0) {
571573
currentStepStartTime = lastStepStartTime.plus(1, ChronoUnit.MILLIS);
572574
}
573575
}

src/test/java/com/epam/reportportal/karate/timing/SimpleTimingTest.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
import com.epam.ta.reportportal.ws.model.StartTestItemRQ;
2424
import com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ;
2525
import com.intuit.karate.Results;
26+
import io.reactivex.Maybe;
2627
import org.junit.jupiter.api.BeforeEach;
2728
import org.junit.jupiter.params.ParameterizedTest;
28-
import org.junit.jupiter.params.provider.ValueSource;
29+
import org.junit.jupiter.params.provider.Arguments;
30+
import org.junit.jupiter.params.provider.MethodSource;
2931
import org.mockito.ArgumentCaptor;
3032

31-
import java.util.Date;
3233
import java.util.List;
3334
import java.util.stream.Collectors;
3435
import java.util.stream.Stream;
@@ -54,13 +55,29 @@ public void setupMock() {
5455
mockBatchLogging(client);
5556
}
5657

58+
public static Stream<Arguments> testCases() {
59+
return Stream.of( //
60+
Arguments.of(false, false), //
61+
Arguments.of(false, true), //
62+
Arguments.of(true, false), //
63+
Arguments.of(true, true) //
64+
);
65+
}
66+
67+
@SuppressWarnings({ "rawtypes", "unchecked" })
5768
@ParameterizedTest
58-
@ValueSource(booleans = { true, false })
59-
public void test_each_item_has_correct_start_date(boolean report) {
69+
@MethodSource("testCases")
70+
public void test_each_item_has_correct_start_date(boolean report, boolean useMicroseconds) {
6071
Results results;
6172
if (report) {
73+
if (useMicroseconds) {
74+
when(client.getApiInfo()).thenReturn(Maybe.just(TestUtils.testApiInfo()));
75+
}
6276
results = TestUtils.runAsReport(rp, TEST_FEATURE);
6377
} else {
78+
if (useMicroseconds) {
79+
when(client.getApiInfo()).thenReturn(Maybe.just(TestUtils.testApiInfo()));
80+
}
6481
results = TestUtils.runAsHook(rp, TEST_FEATURE);
6582
}
6683
assertThat(results.getFailCount(), equalTo(0));
@@ -80,13 +97,13 @@ public void test_each_item_has_correct_start_date(boolean report) {
8097

8198
assertThat(
8299
"Launch start time is greater than Feature start time.",
83-
(Date) featureRq.getStartTime(),
84-
greaterThanOrEqualTo((Date) launchRq.getStartTime())
100+
(Comparable) featureRq.getStartTime(),
101+
greaterThanOrEqualTo((Comparable) launchRq.getStartTime())
85102
);
86103
assertThat(
87104
"Feature start time is greater than Scenario start time.",
88-
(Date) scenarioRq.getStartTime(),
89-
greaterThanOrEqualTo((Date) featureRq.getStartTime())
105+
(Comparable) scenarioRq.getStartTime(),
106+
greaterThanOrEqualTo((Comparable) featureRq.getStartTime())
90107
);
91108

92109
List<StartTestItemRQ> steps = stepCaptor.getAllValues();
@@ -98,19 +115,19 @@ public void test_each_item_has_correct_start_date(boolean report) {
98115
.orElseThrow();
99116

100117
assertThat(
101-
"Scenario start time is greater than Step start time.",
102-
(Date) firstStep.getStartTime(),
103-
greaterThanOrEqualTo((Date) scenarioRq.getStartTime())
118+
"First Step start time is greater or equal than Scenario start time.",
119+
(Comparable) firstStep.getStartTime(),
120+
greaterThanOrEqualTo((Comparable) scenarioRq.getStartTime())
104121
);
105122
assertThat(
106-
"First Step start time is greater or equal than Second Step start time.",
107-
(Date) secondStep.getStartTime(),
108-
greaterThan((Date) firstStep.getStartTime())
123+
"Second Step start time is greater than First Step start time.",
124+
(Comparable) secondStep.getStartTime(),
125+
greaterThan((Comparable) firstStep.getStartTime())
109126
);
110127
assertThat(
111-
"Second Step start time is greater or equal than Third Step start time.",
112-
(Date) thirdStep.getStartTime(),
113-
greaterThan((Date) secondStep.getStartTime())
128+
"Third Step start time is greater than Second Step start time.",
129+
(Comparable) thirdStep.getStartTime(),
130+
greaterThan((Comparable) secondStep.getStartTime())
114131
);
115132
}
116133
}

src/test/java/com/epam/reportportal/karate/utils/TestUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import com.epam.reportportal.karate.KarateReportPortalRunner;
2020
import com.epam.reportportal.karate.ReportPortalHook;
2121
import com.epam.reportportal.listeners.ListenerParameters;
22+
import com.epam.reportportal.service.LaunchImpl;
2223
import com.epam.reportportal.service.ReportPortal;
2324
import com.epam.reportportal.service.ReportPortalClient;
2425
import com.epam.reportportal.util.test.CommonUtils;
2526
import com.epam.reportportal.utils.http.HttpRequestUtils;
27+
import com.epam.ta.reportportal.ws.model.ApiInfo;
2628
import com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS;
2729
import com.epam.ta.reportportal.ws.model.Constants;
2830
import com.epam.ta.reportportal.ws.model.OperationCompletionRS;
@@ -250,4 +252,12 @@ public static List<Pair<String, byte[]>> extractBinaryParts(List<MultipartBody.P
250252
})
251253
.collect(Collectors.toList());
252254
}
255+
256+
public static ApiInfo testApiInfo() {
257+
ApiInfo apiInfo = new ApiInfo();
258+
ApiInfo.Build build = new ApiInfo.Build();
259+
apiInfo.setBuild(build);
260+
build.setVersion(LaunchImpl.MICROSECONDS_MIN_VERSION);
261+
return apiInfo;
262+
}
253263
}

0 commit comments

Comments
 (0)