partially-fixed the tests and benchmarks.
This commit is contained in:
parent
5ad52fa4b2
commit
e07683c046
@ -74,27 +74,21 @@ lazy_static! {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
struct TempDB(tempdir::TempDir, PathBuf, utils::Pool);
|
struct TempDB(tempdir::TempDir, PathBuf, utils::Pool);
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
extern crate rand;
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate tempdir;
|
extern crate tempdir;
|
||||||
#[cfg(test)]
|
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
/// Create and return a Temporary DB.
|
/// Create and return a Temporary DB.
|
||||||
/// Will be destroed once the returned variable(s) is dropped.
|
/// Will be destroed once the returned variable(s) is dropped.
|
||||||
fn get_temp_db() -> TempDB {
|
fn get_temp_db() -> TempDB {
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
|
|
||||||
let tmp_dir = tempdir::TempDir::new("hammond_unit_test").unwrap();
|
let tmp_dir = tempdir::TempDir::new("hammond_unit_test").unwrap();
|
||||||
let db_path = tmp_dir
|
let db_path = tmp_dir.path().join("test.db");
|
||||||
.path()
|
|
||||||
.join("test.db");
|
|
||||||
|
|
||||||
let pool = utils::init_pool(db_path.to_str().unwrap());
|
let pool = utils::init_pool(db_path.to_str().unwrap());
|
||||||
|
{
|
||||||
let db = pool.clone().get().unwrap();
|
let db = pool.clone().get().unwrap();
|
||||||
utils::run_migration_on(&*db).unwrap();
|
utils::run_migration_on(&*db).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
TempDB(tmp_dir, db_path, pool)
|
TempDB(tmp_dir, db_path, pool)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use diesel::prelude::*;
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use r2d2;
|
use r2d2;
|
||||||
@ -12,24 +11,28 @@ use models::Episode;
|
|||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use DB_PATH;
|
use POOL;
|
||||||
|
|
||||||
embed_migrations!("migrations/");
|
embed_migrations!("migrations/");
|
||||||
|
|
||||||
pub type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
|
pub type Pool = Arc<r2d2::Pool<ConnectionManager<SqliteConnection>>>;
|
||||||
|
|
||||||
pub fn init() -> Result<()> {
|
pub fn init() -> Result<()> {
|
||||||
let conn = establish_connection();
|
let con = POOL.clone().get().unwrap();
|
||||||
run_migration_on(&conn)
|
run_migration_on(&*con)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_pool(db_path: &str) -> Pool {
|
pub fn init_pool(db_path: &str) -> Pool {
|
||||||
let config = r2d2::Config::default();
|
let config = r2d2::Config::builder()
|
||||||
|
.connection_timeout(Duration::from_secs(60))
|
||||||
|
.build();
|
||||||
let manager = ConnectionManager::<SqliteConnection>::new(db_path);
|
let manager = ConnectionManager::<SqliteConnection>::new(db_path);
|
||||||
let pool = r2d2::Pool::new(config, manager).expect("Failed to create pool.");
|
let pool = r2d2::Pool::new(config, manager).expect("Failed to create pool.");
|
||||||
info!("Database pool initialized.");
|
info!("Database pool initialized.");
|
||||||
pool
|
Arc::new(pool)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
||||||
@ -39,12 +42,6 @@ pub fn run_migration_on(connection: &SqliteConnection) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn establish_connection() -> SqliteConnection {
|
|
||||||
let database_url = DB_PATH.to_str().unwrap();
|
|
||||||
SqliteConnection::establish(database_url)
|
|
||||||
.expect(&format!("Error connecting to {}", database_url))
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Write unit test.
|
// TODO: Write unit test.
|
||||||
fn download_checker() -> Result<()> {
|
fn download_checker() -> Result<()> {
|
||||||
let episodes = dbqueries::get_downloaded_episodes()?;
|
let episodes = dbqueries::get_downloaded_episodes()?;
|
||||||
|
|||||||
@ -19,11 +19,7 @@ thread_local!(static GLOBAL: Foo = RefCell::new(None));
|
|||||||
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
|
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
|
||||||
/// `delay` represents the desired time in seconds for the thread to sleep before executing.
|
/// `delay` represents the desired time in seconds for the thread to sleep before executing.
|
||||||
/// When It's done,it queues up a `podcast_view` refresh.
|
/// When It's done,it queues up a `podcast_view` refresh.
|
||||||
pub fn refresh_feed(
|
pub fn refresh_feed(stack: >k::Stack, source: Option<Vec<Source>>, delay: Option<u64>) {
|
||||||
stack: >k::Stack,
|
|
||||||
source: Option<Vec<Source>>,
|
|
||||||
delay: Option<u64>,
|
|
||||||
) {
|
|
||||||
// Create a async channel.
|
// Create a async channel.
|
||||||
let (sender, receiver) = channel();
|
let (sender, receiver) = channel();
|
||||||
|
|
||||||
|
|||||||
@ -68,23 +68,19 @@ fn epidose_widget(episode: &mut Episode, pd_title: &str) -> gtk::Box {
|
|||||||
delete_button.show();
|
delete_button.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
play_button.connect_clicked(
|
play_button.connect_clicked(clone!(episode, played_button, unplayed_button => move |_| {
|
||||||
clone!(episode, played_button, unplayed_button => move |_| {
|
|
||||||
on_play_bttn_clicked(*episode.id());
|
on_play_bttn_clicked(*episode.id());
|
||||||
let _ = set_played_now(&mut episode.clone());
|
let _ = set_played_now(&mut episode.clone());
|
||||||
played_button.hide();
|
played_button.hide();
|
||||||
unplayed_button.show();
|
unplayed_button.show();
|
||||||
}),
|
}));
|
||||||
);
|
|
||||||
|
|
||||||
delete_button.connect_clicked(
|
delete_button.connect_clicked(clone!(episode, play_button, download_button => move |del| {
|
||||||
clone!(episode, play_button, download_button => move |del| {
|
|
||||||
on_delete_bttn_clicked(*episode.id());
|
on_delete_bttn_clicked(*episode.id());
|
||||||
del.hide();
|
del.hide();
|
||||||
play_button.hide();
|
play_button.hide();
|
||||||
download_button.show();
|
download_button.show();
|
||||||
}),
|
}));
|
||||||
);
|
|
||||||
|
|
||||||
played_button.connect_clicked(clone!(episode, unplayed_button => move |played| {
|
played_button.connect_clicked(clone!(episode, unplayed_button => move |played| {
|
||||||
let _ = set_played_now(&mut episode.clone());
|
let _ = set_played_now(&mut episode.clone());
|
||||||
@ -101,8 +97,7 @@ fn epidose_widget(episode: &mut Episode, pd_title: &str) -> gtk::Box {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
let pd_title = pd_title.to_owned();
|
let pd_title = pd_title.to_owned();
|
||||||
download_button.connect_clicked(
|
download_button.connect_clicked(clone!(play_button, delete_button, episode => move |dl| {
|
||||||
clone!(play_button, delete_button, episode => move |dl| {
|
|
||||||
on_download_clicked(
|
on_download_clicked(
|
||||||
&pd_title,
|
&pd_title,
|
||||||
&mut episode.clone(),
|
&mut episode.clone(),
|
||||||
@ -110,8 +105,7 @@ fn epidose_widget(episode: &mut Episode, pd_title: &str) -> gtk::Box {
|
|||||||
&play_button,
|
&play_button,
|
||||||
&delete_button,
|
&delete_button,
|
||||||
);
|
);
|
||||||
}),
|
}));
|
||||||
);
|
|
||||||
|
|
||||||
ep
|
ep
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,11 +53,7 @@ pub fn podcast_widget(stack: >k::Stack, pd: &Podcast) -> gtk::Box {
|
|||||||
pd_widget
|
pd_widget
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_unsub_button_clicked(
|
fn on_unsub_button_clicked(stack: >k::Stack, pd: &Podcast, unsub_button: >k::Button) {
|
||||||
stack: >k::Stack,
|
|
||||||
pd: &Podcast,
|
|
||||||
unsub_button: >k::Button,
|
|
||||||
) {
|
|
||||||
let res = dbqueries::remove_feed(pd);
|
let res = dbqueries::remove_feed(pd);
|
||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
info!("{} was removed succesfully.", pd.title());
|
info!("{} was removed succesfully.", pd.title());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user