Skip to content

WebSocket tests are flaky #246

@benmanns

Description

@benmanns

When working on #244 and #245, I noticed that the tests can fail successfully if no messages are produced.

@test "websocket-connector-test" {
    count=1
    echo "Starting consumer on topic $TOPIC"
    sleep 13

    fluvio consume -B -d $TOPIC | while read input; do
        expected="Hello, Fluvio! - $count"
        echo $input = $expected
        [ "$input" = "$expected" ]
        count=$(($count + 1))
        if [ $count -eq 10 ]; then
            break;
        fi
    done

}

If fluvio consume -B -d $TOPIC produced no lines, nothing gets tested. I tested a new method that I think works pretty well:

@test "websocket-connector-test" {
    count=1
    echo "Starting consumer on topic $TOPIC"
    sleep 13

    expected=<<EOF
Hello, Fluvio! - 1
Hello, Fluvio! - 2
Hello, Fluvio! - 3
Hello, Fluvio! - 4
Hello, Fluvio! - 5
Hello, Fluvio! - 6
Hello, Fluvio! - 7
Hello, Fluvio! - 8
Hello, Fluvio! - 9
Hello, Fluvio! - 10
EOF

    run fluvio consume -B -d $TOPIC

    [[ $output = $expected* ]]
}

I check against $expected as a prefix because the tests tend to exit and re-run which duplicates the output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions