[
https://issues.apache.org/jira/browse/AVRO-4230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18058999#comment-18058999
]
Todd McDowell commented on AVRO-4230:
-------------------------------------
Added a unit test for this change.
The new test fails non-deterministically fails on the original code. It
occasionally passes the new test when Perl's keys function happens to return
the keys in sorted order.. With the code change to add the sort, the new test
always passes.
Interestingly, there weren't any tests that executed the encode_map sub in
02_bin_encode.t. The encode_map sub was executed in 03_bin_decode.t in order to
set up for the decoding tests.
> Avro::BinaryEncoder's encode_map generates non-deterministic output which
> makes writing unit tests more difficult
> -----------------------------------------------------------------------------------------------------------------
>
> Key: AVRO-4230
> URL: https://issues.apache.org/jira/browse/AVRO-4230
> Project: Apache Avro
> Issue Type: Improvement
> Components: perl
> Affects Versions: 1.12.1
> Reporter: Todd McDowell
> Priority: Minor
> Labels: pull-request-available
> Original Estimate: 2h
> Time Spent: 1h 20m
> Remaining Estimate: 40m
>
> I was attempting to write unit tests for Perl code that was making use of
> Avro::BinaryEncoder. The code was specifically calling encode_map, which
> encodes a Perl hash into binary. However, since Perl's keys function does
> not guarantee a consistent order of the hash's keys, the expected value from
> encode_map occasionally fails to match the observed value, which causes the
> test to fail.
> I recommend sorting the keys of the data in encode_map before the encoding
> process to ensure a deterministic output from encode_map. I've already
> modified the code, but I needed to submit this issue before I could submit
> the pull request change based on the instructions I read. The deterministic
> output from encode_map will make testing simpler. I'll submit that change
> for review shortly.
> Thanks for your attention.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)