Skip to content

Commit

Permalink
readyset-psql: Use new table/enum in types::enums()
Browse files Browse the repository at this point in the history
We are (yet again) still hitting a race in the `types::enum()` test
between dropping a table and enum, recreating them, and being able to
use them from within the readyset test. This patch eschews the drop
and recreate for just creating new a table and enum (for the subset of
this long test function that actually will use them).

Change-Id: Ib24914e52f25d523a88c51d15b1baf420db4caeb
Reviewed-on: https://gerrit.readyset.name/c/readyset/+/7403
Tested-by: Buildkite CI
Reviewed-by: Ethan Donowitz <ethan@readyset.io>
  • Loading branch information
jasobrown-rs committed Apr 29, 2024
1 parent 5fca15b commit 6c78867
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions readyset-psql/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,32 +550,54 @@ mod types {
QueryDestination::Readyset
);

client.simple_query("DROP TABLE enumt;").await.unwrap();
client.simple_query("DROP TYPE abc CASCADE").await.unwrap();

client
.simple_query("CREATE TYPE abc AS ENUM ('c', 'b', 'a');")
.simple_query("CREATE TYPE abc_rev AS ENUM ('c', 'b', 'a');")
.await
.unwrap();

client
.simple_query("CREATE TABLE enumt (x abc);")
.simple_query("CREATE TABLE enumt2 (x abc_rev);")
.await
.unwrap();

client
.simple_query("INSERT INTO enumt (x) VALUES ('b'), ('c'), ('a'), ('a')")
.simple_query("INSERT INTO enumt2 (x) VALUES ('b'), ('c'), ('a'), ('a')")
.await
.unwrap();

sleep().await;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
enum AbcRev {
C,
B,
A,
}

impl<'a> FromSql<'a> for AbcRev {
fn from_sql(
_ty: &postgres_types::Type,
raw: &'a [u8],
) -> Result<Self, Box<dyn std::error::Error + Sync + Send>> {
match raw {
b"a" => Ok(Self::A),
b"b" => Ok(Self::B),
b"c" => Ok(Self::C),
r => Err(format!("Unknown variant: '{}'", String::from_utf8_lossy(r)).into()),
}
}

fn accepts(ty: &postgres_types::Type) -> bool {
ty.name() == "abc_rev"
}
}

client
.simple_query("CREATE CACHE FROM SELECT x FROM enumt ORDER BY x ASC")
.simple_query("CREATE CACHE FROM SELECT x FROM enumt2 ORDER BY x ASC")
.await
.unwrap();
let _ = client
.query("SELECT x FROM enumt ORDER BY x ASC", &[])
.query("SELECT x FROM enumt2 ORDER BY x ASC", &[])
.await;

// wrapping this test in an eventually! macro as it frequently fails in CI.
Expand All @@ -584,15 +606,15 @@ mod types {
eventually!(
run_test: {
client
.query("SELECT x FROM enumt ORDER BY x ASC", &[])
.query("SELECT x FROM enumt2 ORDER BY x ASC", &[])
.await
.unwrap()
.into_iter()
.map(|r| r.get(0))
.collect::<Vec<Abc>>()
.collect::<Vec<AbcRev>>()
},
then_assert: |sort_res| {
assert_eq!(sort_res, vec![C, B, A, A]);
assert_eq!(sort_res, vec![AbcRev::C, AbcRev::B, AbcRev::A, AbcRev::A]);
}
);

Expand All @@ -604,7 +626,7 @@ mod types {
// Rename the type

client
.simple_query("ALTER TYPE abc RENAME TO cba")
.simple_query("ALTER TYPE abc_rev RENAME TO cba")
.await
.unwrap();
client
Expand Down

0 comments on commit 6c78867

Please sign in to comment.