Skip to content

Commit

Permalink
tests(cockroach): fix a flaky cockroach test (#3602)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky authored Jan 19, 2023
1 parent 1df3eac commit ef34c0d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,29 @@ macro_rules! assert_error {
$runner.query($q).await?.assert_failure($code, Some($msg.to_string()));
};
}

#[macro_export]
macro_rules! retry {
($body:block, $times:expr) => {{
use std::time::Duration;
use tokio::time::sleep;

let mut retries = $times;

loop {
let res = $body.await?;

if !res.failed() {
break res;
}

if retries > 0 {
retries -= 1;
sleep(Duration::from_millis(5)).await;
continue;
}

break res;
}
}};
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,32 @@ mod create {
// "A Create Mutation" should "create and return item"
#[connector_test]
async fn create_should_work(runner: Runner) -> TestResult<()> {
// This test is flaky on CockroachDB because of a TX write conflict.
// We mitigate this issue by retrying multiple times.
let res = retry!(
{
runner.query(format!(
r#"mutation {{
createOneScalarModel(data: {{
id: "1",
optString: "lala{}",
optInt: 1337,
optFloat: 1.234,
optBoolean: true,
optEnum: A,
optDateTime: "2016-07-31T23:59:01.000Z"
}}) {{
id, optString, optInt, optFloat, optBoolean, optEnum, optDateTime
}}
}}"#,
TROUBLE_CHARS
))
},
5
);

insta::assert_snapshot!(
run_query!(
runner,
format!(
r#"mutation {{
createOneScalarModel(data: {{
id: "1",
optString: "lala{}",
optInt: 1337,
optFloat: 1.234,
optBoolean: true,
optEnum: A,
optDateTime: "2016-07-31T23:59:01.000Z"
}}) {{
id, optString, optInt, optFloat, optBoolean, optEnum, optDateTime
}}
}}"#,
TROUBLE_CHARS
)
),
res.to_string(),
@r###"{"data":{"createOneScalarModel":{"id":"1","optString":"lalaยฅเธฟ๐Ÿ˜€๐Ÿ˜๐Ÿ˜‚๐Ÿ˜ƒ๐Ÿ˜„๐Ÿ˜…๐Ÿ˜†๐Ÿ˜‡๐Ÿ˜ˆ๐Ÿ˜‰๐Ÿ˜Š๐Ÿ˜‹๐Ÿ˜Œ๐Ÿ˜๐Ÿ˜Ž๐Ÿ˜๐Ÿ˜๐Ÿ˜‘๐Ÿ˜’๐Ÿ˜“๐Ÿ˜”๐Ÿ˜•๐Ÿ˜–๐Ÿ˜—๐Ÿ˜˜๐Ÿ˜™๐Ÿ˜š๐Ÿ˜›๐Ÿ˜œ๐Ÿ˜๐Ÿ˜ž๐Ÿ˜Ÿ๐Ÿ˜ ๐Ÿ˜ก๐Ÿ˜ข๐Ÿ˜ฃ๐Ÿ˜ค๐Ÿ˜ฅ๐Ÿ˜ฆ๐Ÿ˜ง๐Ÿ˜จ๐Ÿ˜ฉ๐Ÿ˜ช๐Ÿ˜ซ๐Ÿ˜ฌ๐Ÿ˜ญ๐Ÿ˜ฎ๐Ÿ˜ฏ๐Ÿ˜ฐ๐Ÿ˜ฑ๐Ÿ˜ฒ๐Ÿ˜ณ๐Ÿ˜ด๐Ÿ˜ต๐Ÿ˜ถ๐Ÿ˜ท๐Ÿ˜ธ๐Ÿ˜น๐Ÿ˜บ๐Ÿ˜ป๐Ÿ˜ผ๐Ÿ˜ฝ๐Ÿ˜พ๐Ÿ˜ฟ๐Ÿ™€๐Ÿ™๐Ÿ™‚๐Ÿ™ƒ๐Ÿ™„๐Ÿ™…๐Ÿ™†๐Ÿ™‡๐Ÿ™ˆ๐Ÿ™‰๐Ÿ™Š๐Ÿ™‹๐Ÿ™Œ๐Ÿ™๐Ÿ™Ž๐Ÿ™เค€เคเค‚เคƒเค„เค…เค†เค‡เคˆเค‰เคŠเค‹เคŒเคเคŽเคเคเค‘เค’เค“เค”เค•เค–เค—เค˜เค™เคšเค›เคœเคเคžเคŸเค เคกเคขเคฃเคคเคฅเคฆเคงเคจเคฉเคชเคซเคฌเคญเคฎเคฏเคฐโ‚ฌโ‚ญโ‚ฎโ‚ฏโ‚ฐโ‚ฑโ‚ฒโ‚ณโ‚ดโ‚ตโ‚ถโ‚ทโ‚ธโ‚นโ‚บโ‚ปโ‚ผโ‚ฝโ‚พโ‚ฟโƒ€","optInt":1337,"optFloat":1.234,"optBoolean":true,"optEnum":"A","optDateTime":"2016-07-31T23:59:01.000Z"}}}"###
);

Expand Down

0 comments on commit ef34c0d

Please sign in to comment.