Inconsistent output inside `For` with branching
emil14 opened this issue · 7 comments
emil14 commented
Output isn't consistent
component Main(start) (stop) {
nodes { For{Printer}, Range }
:start -> [(1 -> range:from), (11 -> range:to)]
range -> for -> :stop
}
component Printer(data int) (sig any) {
nodes { Even, PrintTwice, If }
:data -> even -> if
if:then -> ('is even' -> printTwice)
if:else -> ('is odd' -> printTwice)
printTwice -> :sig
}
component Even(data int) (res bool) {
nodes { Mod }
:data -> mod:data
2 -> mod:case[0] -> (true -> :res)
mod:else -> (false -> :res)
}
component PrintTwice(data string) (sig any) {
nodes { p1 Println, p2 Println }
:data -> p1 -> p2 -> :sig
}
Related to #575
emil14 commented
Here's e2e
package test
import (
"os/exec"
"testing"
"github.com/stretchr/testify/require"
)
func Test(t *testing.T) {
cmd := exec.Command("neva", "run", "main")
out, err := cmd.CombinedOutput()
require.NoError(t, err)
require.Equal(
t,
`is odd
is odd
is even
is even
is odd
is odd
is even
is even
is odd
is odd
is even
is even
is odd
is odd
is even
is even
is odd
is odd
is even
is even
`,
string(out),
)
require.Equal(t, 0, cmd.ProcessState.ExitCode())
}
Catya3 commented
printSlow
version will also trigger the bug
component PrintSlow(data string) (sig any) {
nodes { p1 Println, time.Sleep }
200000000 -> sleep:dur // 200 ms
:data -> p1 -> sleep:data -> :sig
}
Catya3 commented
Just to be pedantic, #575 is about early termination whereas this one is about items printed out of order. Is that a correct interpretation?
emil14 commented
@Catya3 yeah, don't sure if they are related
unpredictable termination was because of branching, basically data-race
this one also looks like some kind of race
Catya3 commented
It looks like For actually fixes the unpredictable termination and now we have items executed out of order. Not sure what causes it
emil14 commented
Yeah I think the same. I just wanna keep 575 opened until we fix this one, just to be sure