Hang Xie created FLINK-24569:
--------------------------------
Summary: Flaky Test in NFATest
Key: FLINK-24569
URL: https://issues.apache.org/jira/browse/FLINK-24569
Project: Flink
Issue Type: Improvement
Reporter: Hang Xie
I noticed there is a potential flaky test in org.apache.flink.cep.nfa.NFATest
file.
For example, in the "testNFASerialization" test, ** we try to compare the
deserialization result of nfaState and its copy. However, I noticed that to
compare whether two nfaState objects are equal, we need to check whether their
partialMatches and completedMatches are equal.
"partialMatches" and "completedMatches" are two priority queues, and when we
need to compare whether these two priority queues are the same, we need to
first cast both priority queues to arrays.
I noticed we write a customized COMPUTATION_STATE_COMPARATOR for both priority
queues. However, this comparator only compares the event's timestamp and id.
If, in some cases, we have two events who share the same timestamp and id, but
have different version, or we have two events without timestamp and id, their
order in the priority queues will than become indeterministic.
Here is what the official documentation says about the order in priority queue
(https://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html):
{quote}This class and its iterator implement all of the _optional_ methods of
the
[Collection|https://docs.oracle.com/javase/7/docs/api/java/util/Collection.html]
and
[Iterator|https://docs.oracle.com/javase/7/docs/api/java/util/Iterator.html]
interfaces. The Iterator provided in method
[iterator()|https://docs.oracle.com/javase/7/docs/api/java/util/PriorityQueue.html#iterator()]
is _not_ guaranteed to traverse the elements of the priority queue in any
particular order. If you need ordered traversal, consider using
Arrays.sort(pq.toArray()).
{quote}
Thus, the assertion
(flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/nfa/NFATest.java:372)
here will fail in some platforms or specific machines that adopt a different
iteration order.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)