Skip to content

Commit ec9a15b

Browse files
committed
Fix tests
1 parent 134cbf8 commit ec9a15b

File tree

2 files changed

+65
-52
lines changed

2 files changed

+65
-52
lines changed

src/conn/mod.rs

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,34 +1544,28 @@ mod test {
15441544
#[tokio::test]
15451545
async fn should_reset_the_connection() -> super::Result<()> {
15461546
let mut conn = Conn::new(get_opts()).await?;
1547-
let max_execution_time = conn
1548-
.query_first::<u64, _>("SELECT @@max_execution_time")
1549-
.await?
1550-
.unwrap();
15511547

1552-
conn.exec_drop(
1553-
"SET SESSION max_execution_time = ?",
1554-
(max_execution_time + 1,),
1555-
)
1556-
.await?;
1548+
assert_eq!(
1549+
conn.query_first::<Value, _>("SELECT @foo").await?.unwrap(),
1550+
Value::NULL
1551+
);
1552+
1553+
conn.query_drop("SET @foo = 'foo'").await?;
15571554

15581555
assert_eq!(
1559-
conn.query_first::<u64, _>("SELECT @@max_execution_time")
1560-
.await?,
1561-
Some(max_execution_time + 1)
1556+
conn.query_first::<String, _>("SELECT @foo").await?.unwrap(),
1557+
"foo",
15621558
);
15631559

15641560
if conn.reset().await? {
15651561
assert_eq!(
1566-
conn.query_first::<u64, _>("SELECT @@max_execution_time")
1567-
.await?,
1568-
Some(max_execution_time)
1562+
conn.query_first::<Value, _>("SELECT @foo").await?.unwrap(),
1563+
Value::NULL
15691564
);
15701565
} else {
15711566
assert_eq!(
1572-
conn.query_first::<u64, _>("SELECT @@max_execution_time")
1573-
.await?,
1574-
Some(max_execution_time + 1)
1567+
conn.query_first::<String, _>("SELECT @foo").await?.unwrap(),
1568+
"foo",
15751569
);
15761570
}
15771571

@@ -1582,28 +1576,22 @@ mod test {
15821576
#[tokio::test]
15831577
async fn should_change_user() -> super::Result<()> {
15841578
let mut conn = Conn::new(get_opts()).await?;
1585-
let max_execution_time = conn
1586-
.query_first::<u64, _>("SELECT @@max_execution_time")
1587-
.await?
1588-
.unwrap();
1579+
assert_eq!(
1580+
conn.query_first::<Value, _>("SELECT @foo").await?.unwrap(),
1581+
Value::NULL
1582+
);
15891583

1590-
conn.exec_drop(
1591-
"SET SESSION max_execution_time = ?",
1592-
(max_execution_time + 1,),
1593-
)
1594-
.await?;
1584+
conn.query_drop("SET @foo = 'foo'").await?;
15951585

15961586
assert_eq!(
1597-
conn.query_first::<u64, _>("SELECT @@max_execution_time")
1598-
.await?,
1599-
Some(max_execution_time + 1)
1587+
conn.query_first::<String, _>("SELECT @foo").await?.unwrap(),
1588+
"foo",
16001589
);
16011590

16021591
conn.change_user(Default::default()).await?;
16031592
assert_eq!(
1604-
conn.query_first::<u64, _>("SELECT @@max_execution_time")
1605-
.await?,
1606-
Some(max_execution_time)
1593+
conn.query_first::<Value, _>("SELECT @foo").await?.unwrap(),
1594+
Value::NULL
16071595
);
16081596

16091597
let plugins: &[&str] = if !conn.inner.is_mariadb && conn.server_version() >= (5, 8, 0) {
@@ -1613,42 +1601,67 @@ mod test {
16131601
};
16141602

16151603
for plugin in plugins {
1616-
let mut conn2 = Conn::new(get_opts()).await.unwrap();
1617-
16181604
let mut rng = rand::thread_rng();
16191605
let mut pass = [0u8; 10];
16201606
pass.try_fill(&mut rng).unwrap();
16211607
let pass: String = IntoIterator::into_iter(pass)
16221608
.map(|x| ((x % (123 - 97)) + 97) as char)
16231609
.collect();
1624-
conn.query_drop("DROP USER IF EXISTS __mysql_async_test_user")
1610+
1611+
conn.query_drop("DELETE FROM mysql.user WHERE user = '__mats'")
16251612
.await
16261613
.unwrap();
1627-
conn.query_drop(format!(
1628-
"CREATE USER '__mysql_async_test_user'@'%' IDENTIFIED WITH {} BY {}",
1629-
plugin,
1630-
Value::from(pass.clone()).as_sql(false)
1631-
))
1632-
.await
1633-
.unwrap();
16341614
conn.query_drop("FLUSH PRIVILEGES").await.unwrap();
16351615

1616+
if conn.inner.is_mariadb || conn.server_version() < (5, 7, 0) {
1617+
if matches!(conn.server_version(), (5, 6, _)) {
1618+
conn.query_drop("CREATE USER '__mats'@'%' IDENTIFIED WITH mysql_old_password")
1619+
.await
1620+
.unwrap();
1621+
conn.query_drop(format!(
1622+
"SET PASSWORD FOR '__mats'@'%' = OLD_PASSWORD({})",
1623+
Value::from(pass.clone()).as_sql(false)
1624+
))
1625+
.await
1626+
.unwrap();
1627+
} else {
1628+
conn.query_drop("CREATE USER '__mats'@'%'").await.unwrap();
1629+
conn.query_drop(format!(
1630+
"SET PASSWORD FOR '__mats'@'%' = PASSWORD({})",
1631+
Value::from(pass.clone()).as_sql(false)
1632+
))
1633+
.await
1634+
.unwrap();
1635+
}
1636+
} else {
1637+
conn.query_drop(format!(
1638+
"CREATE USER '__mats'@'%' IDENTIFIED WITH {} BY {}",
1639+
plugin,
1640+
Value::from(pass.clone()).as_sql(false)
1641+
))
1642+
.await
1643+
.unwrap();
1644+
};
1645+
1646+
conn.query_drop("FLUSH PRIVILEGES").await.unwrap();
1647+
1648+
let mut conn2 = Conn::new(get_opts().secure_auth(false)).await.unwrap();
16361649
conn2
16371650
.change_user(
16381651
ChangeUserOpts::default()
16391652
.with_db_name(None)
1640-
.with_user(Some("__mysql_async_test_user".into()))
1653+
.with_user(Some("__mats".into()))
16411654
.with_pass(Some(pass)),
16421655
)
16431656
.await
16441657
.unwrap();
1645-
assert_eq!(
1646-
conn2
1647-
.query_first::<(Option<String>, String), _>("SELECT DATABASE(), USER();")
1648-
.await
1649-
.unwrap(),
1650-
Some((None, String::from("__mysql_async_test_user@localhost"))),
1651-
);
1658+
let (db, user) = conn2
1659+
.query_first::<(Option<String>, String), _>("SELECT DATABASE(), USER();")
1660+
.await
1661+
.unwrap()
1662+
.unwrap();
1663+
assert_eq!(db, None);
1664+
assert!(user.starts_with("__mats"));
16521665

16531666
conn2.disconnect().await.unwrap();
16541667
}

src/conn/pool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ mod test {
666666
let _ = conns.pop();
667667

668668
// then, wait for a bit to let the connection be reclaimed
669-
sleep(Duration::from_millis(50)).await;
669+
sleep(Duration::from_millis(500)).await;
670670

671671
// now check that we have the expected # of connections
672672
// this may look a little funky, but think of it this way:

0 commit comments

Comments
 (0)