tremor-rs / tremor-runtime

Main Tremor Project Rust Codebase
https://www.tremor.rs
Apache License 2.0
852 stars 125 forks source link

EQC model failed #2141

Open Licenser opened 1 year ago

Licenser commented 1 year ago

Problem EQC model failed:

[{model,test_eqc},
 {set,{var,1},{call,test_eqc,let_local,[[],<<"bedebcc">>,{int,1}]}},
 {set,{var,2},
      {call,test_eqc,expr,
            [[{'let',{local,<<"bedebcc">>},1}],
             {array,[{patch,{record,#{<<"Bg==">> => {local,<<"bedebcc">>}}},
                            [{merge,{record,#{<<"Bg==">> => 2}}}]}]}]}}]

test_eqc:let_local([], <<"bedebcc">>, {int, 1}) -> #{<<"emit">> => 1}
test_eqc:expr([{'let', {local, <<"bedebcc">>}, 1}],
    {array,
       [{patch, {record, #{<<"Bg==">> => {local, <<"bedebcc">>}}},
           [{merge, {record, #{<<"Bg==">> => 2}}}]}]}) ->
  #{<<"emit">> => [#{<<"Bg==">> => 2}]}

Reason:
  Post-condition failed:
  {{model, #{<<"emit">> => [#{<<"Bg==">> => 1}]}}, '!=', {rust, #{<<"emit">> => [#{<<"Bg==">> => 2}]}}}
rushi-12320 commented 1 year ago

what is the exact problem

Licenser commented 1 year ago

The problem is a bug in the model, the expression tested is:

let bedebcc = 1;
patch {"Bg==": bedebcc} of
   merge => {"Bg==": 2}
end

which in the rest version correctly evaluates to:

{"Bg==": 2}

but in the model; evaluates to:

{"Bg==": 1}

So to clarify this is a bug in the test not a bug in the code

rushi-12320 commented 1 year ago

which technology or language is used in this bug

Licenser commented 1 year ago

Mostly Erlang, @me-diru could probably give some details.

me-diru commented 1 year ago

Yes, @rushi-12320. The technology used for testing is called EQC or Erlang QuickCheck. It is used here specifically to test the model aka specification of the scripting language called Script/TremorScript (Which is written in Rust but is inspired from Erlang). The one metioned in the above comment i.e

patch {"Bg==": bedebcc} of
   merge => {"Bg==": 2}
end 

is called patch and the documentation can be found here I am not wrong: https://www.tremor.rs/docs/0.12/language/expressions#patch

The tests here generate randomised test cases with respect to the model and check with the Rust version of the same expression to measure it's correctness and if it is working as intended.

In this bug specifically, the Rust version evaluates the expression properly and gives as the desired result

{"Bg==": 2}

But the Script/Model output is not right

{"Bg==": 1}

I highly recommend reading the following blog to understand more about this type of testing and the approach used here.

Do let us know if you have more questions!