Skip to content

Commit

Permalink
only use fakerelease.create_async and rename it
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Nov 13, 2024
1 parent 269b522 commit 0549eef
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 285 deletions.
8 changes: 4 additions & 4 deletions src/build_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ mod tests {
.version("0.1.0")
.builds(vec![FakeBuild::default()
.rustc_version("rustc 1.84.0-nightly (e7c0d2750 2020-10-15)")])
.create_async()
.create()
.await?;

let build_queue = env.async_build_queue().await;
Expand Down Expand Up @@ -787,7 +787,7 @@ mod tests {
.version("0.1.0")
.builds(vec![FakeBuild::default()
.rustc_version("rustc 1.84.0-nightly (e7c0d2750 2020-10-15)")])
.create_async()
.create()
.await?;

let build_queue = env.async_build_queue().await;
Expand Down Expand Up @@ -835,7 +835,7 @@ mod tests {
.version("0.1.0")
.builds(vec![FakeBuild::default()
.rustc_version("rustc 1.84.0-nightly (e7c0d2750 2020-10-15)")])
.create_async()
.create()
.await?;

let build_queue = env.async_build_queue().await;
Expand Down Expand Up @@ -869,7 +869,7 @@ mod tests {
.version("0.1.0")
.builds(vec![FakeBuild::default()
.rustc_version("rustc 1.84.0-nightly (e7c0d2750 2020-10-15)")])
.create_async()
.create()
.await?;

let build_queue = env.async_build_queue().await;
Expand Down
20 changes: 12 additions & 8 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ mod test {
.name("dummy")
.version("0.13.0")
.keywords(vec!["kw 1".into(), "kw 2".into()])
.create_async()
.create()
.await?;

let kw_r = sqlx::query!(
Expand Down Expand Up @@ -878,19 +878,23 @@ mod test {

#[test]
fn keyword_conflict_when_rebuilding_release() {
wrapper(|env| {
env.fake_release()
async_wrapper(|env| async move {
env.async_fake_release()
.await
.name("dummy")
.version("0.13.0")
.keywords(vec!["kw 3".into(), "kw 4".into()])
.create()?;
.create()
.await?;

// same version so we have the same release
env.fake_release()
env.async_fake_release()
.await
.name("dummy")
.version("0.13.0")
.keywords(vec!["kw 3".into(), "kw 4".into()])
.create()?;
.create()
.await?;

Ok(())
})
Expand All @@ -904,7 +908,7 @@ mod test {
.name("dummy")
.version("0.13.0")
.keywords(vec!["kw 3".into(), "kw 4".into()])
.create_async()
.create()
.await?;

let release_id = env
Expand All @@ -913,7 +917,7 @@ mod test {
.name("dummy")
.version("0.13.0")
.keywords(vec!["kw 1".into(), "kw 2".into()])
.create_async()
.create()
.await?;

let mut conn = env.async_db().await.async_conn().await;
Expand Down
12 changes: 6 additions & 6 deletions src/db/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ mod tests {
.await
.name("Some_Package")
.version("1.0.0")
.create_async()
.create()
.await?;

let mut conn = env.async_db().await.async_conn().await;
Expand All @@ -269,22 +269,22 @@ mod tests {
.name("package-1")
.version("1.0.0")
.archive_storage(archive_storage)
.create_async()
.create()
.await?;
let pkg1_v2_id = env
.async_fake_release()
.await
.name("package-1")
.version("2.0.0")
.archive_storage(archive_storage)
.create_async()
.create()
.await?;
let pkg2_id = env
.async_fake_release()
.await
.name("package-2")
.archive_storage(archive_storage)
.create_async()
.create()
.await?;

assert!(crate_exists(&mut conn, "package-1").await?);
Expand Down Expand Up @@ -417,7 +417,7 @@ mod tests {
avatar: "https://example.org/malicious".into(),
kind: OwnerKind::User,
})
.create_async()
.create()
.await?;
assert!(release_exists(&mut conn, v1).await?);
assert!(
Expand Down Expand Up @@ -448,7 +448,7 @@ mod tests {
avatar: "https://example.org/peter".into(),
kind: OwnerKind::User,
})
.create_async()
.create()
.await?;
assert!(release_exists(&mut conn, v2).await?);
assert!(
Expand Down
11 changes: 1 addition & 10 deletions src/test/fakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use chrono::{DateTime, Utc};
use std::collections::HashMap;
use std::iter;
use std::sync::Arc;
use tokio::runtime::Runtime;
use tracing::debug;

/// Create a fake release in the database that failed before the build.
Expand Down Expand Up @@ -55,7 +54,6 @@ pub(crate) async fn fake_release_that_failed_before_build(
pub(crate) struct FakeRelease<'a> {
db: &'a TestDatabase,
storage: Arc<AsyncStorage>,
runtime: Arc<Runtime>,
package: MetadataPackage,
builds: Option<Vec<FakeBuild>>,
/// name, content
Expand Down Expand Up @@ -92,12 +90,10 @@ impl<'a> FakeRelease<'a> {
pub(super) fn new(
db: &'a TestDatabase,
storage: Arc<AsyncStorage>,
runtime: Arc<Runtime>,
) -> Self {
FakeRelease {
db,
storage,
runtime,
package: MetadataPackage {
id: "fake-package-id".into(),
name: "fake-package".into(),
Expand Down Expand Up @@ -328,13 +324,8 @@ impl<'a> FakeRelease<'a> {
self
}

pub(crate) fn create(self) -> Result<ReleaseId> {
let runtime = self.runtime.clone();
runtime.block_on(self.create_async())
}

/// Returns the release_id
pub(crate) async fn create_async(self) -> Result<ReleaseId> {
pub(crate) async fn create(self) -> Result<ReleaseId> {
use std::fs;
use std::path::Path;

Expand Down
1 change: 0 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ impl TestEnvironment {
fakes::FakeRelease::new(
self.async_db().await,
self.async_storage().await,
self.runtime(),
)
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/utils/consistency/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ mod tests {
fn test_load() {
wrapper(|env| {
env.build_queue().add_crate("queued", "0.0.1", 0, None)?;
env.fake_release().name("krate").version("0.0.2").create()?;
env.fake_release()
.name("krate")
.version("0.0.3")
.yanked(true)
.create()?;
let runtime = env.runtime();
runtime.block_on(env.fake_release().name("krate").version("0.0.2").create())?;
runtime.block_on(
env.fake_release()
.name("krate")
.version("0.0.3")
.yanked(true)
.create(),
)?;

let result = env.runtime().block_on(async {
let result = runtime.block_on(async {
let mut conn = env.async_db().await.async_conn().await;
load(&mut conn, &env.config()).await
})?;
Expand Down
22 changes: 13 additions & 9 deletions src/utils/consistency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,14 @@ mod tests {
#[test]
fn test_delete_crate() {
wrapper(|env| {
env.fake_release()
.name("krate")
.version("0.1.1")
.version("0.1.2")
.create()?;
let runtime = env.runtime();
runtime.block_on(
env.fake_release()
.name("krate")
.version("0.1.1")
.version("0.1.2")
.create(),
)?;

let diff = [Difference::CrateNotInIndex("krate".into())];

Expand All @@ -215,8 +218,9 @@ mod tests {
#[test]
fn test_delete_release() {
wrapper(|env| {
env.fake_release().name("krate").version("0.1.1").create()?;
env.fake_release().name("krate").version("0.1.2").create()?;
let runtime = env.runtime();
runtime.block_on(env.fake_release().name("krate").version("0.1.1").create())?;
runtime.block_on(env.fake_release().name("krate").version("0.1.2").create())?;

let diff = [Difference::ReleaseNotInIndex(
"krate".into(),
Expand All @@ -243,11 +247,11 @@ mod tests {
#[test]
fn test_wrong_yank() {
wrapper(|env| {
env.fake_release()
env.runtime().block_on(env.fake_release()
.name("krate")
.version("0.1.1")
.yanked(true)
.create()?;
.create())?;

let diff = [Difference::ReleaseYank(
"krate".into(),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod test {
</head>
</html>
"#)
.create_async().await?;
.create().await?;

let web = env.web_app().await;
let output = web.get("/testing/0.1.0/2016/").await?.text().await?;
Expand Down
10 changes: 5 additions & 5 deletions src/web/build_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {
.builds(vec![FakeBuild::default()
.no_s3_build_log()
.db_build_log("A build log")])
.create_async()
.create()
.await?;

let web = env.web_app().await;
Expand Down Expand Up @@ -245,7 +245,7 @@ mod tests {
.name("foo")
.version("0.1.0")
.builds(vec![FakeBuild::default().s3_build_log("A build log")])
.create_async()
.create()
.await?;

let web = env.web_app().await;
Expand Down Expand Up @@ -302,7 +302,7 @@ mod tests {
"other_target",
"other target build log",
)])
.create_async()
.create()
.await?;

let web = env.web_app().await;
Expand Down Expand Up @@ -366,7 +366,7 @@ mod tests {
.builds(vec![FakeBuild::default()
.s3_build_log("A build log")
.db_build_log("Another build log")])
.create_async()
.create()
.await?;

let web = env.web_app().await;
Expand Down Expand Up @@ -399,7 +399,7 @@ mod tests {
.await
.name("foo")
.version("0.1.0")
.create_async()
.create()
.await?;

let res = env
Expand Down
Loading

0 comments on commit 0549eef

Please sign in to comment.