Skip to content

Commit

Permalink
Fix tests and latest Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Nov 6, 2023
1 parent b3b5753 commit 1b17f00
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 120 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,8 @@ unsafe impl<I: AsyncDeallocationIntegration, D: Deallocate> GlobalAlloc
self.sync_deallocator.deallocate(ptr, layout);
}
TrySendError::Disconnected(_) => {
// Should never happen because the receiver is owned by the deallocation thread
// and that thread should live at least as long as the sender
panic!("deallocation thread is dead");
// Could happen on shutdown
self.sync_deallocator.deallocate(ptr, layout);
}
}
}
Expand Down Expand Up @@ -285,26 +284,27 @@ mod tests {
static GLOBAL_ALLOCATOR: HelgobossAllocator<TestIntegration, TestDeallocator> =
HelgobossAllocator::new(TestDeallocator("SYNC"));

fn init() {
GLOBAL_ALLOCATOR.init(100, TestIntegration);
fn init() -> AsyncDeallocatorCommandReceiver {
GLOBAL_ALLOCATOR.init(100, TestIntegration)
}

#[test]
fn offload_deallocate() {
init();
let _receiver = init();
let mut bla = vec![];
bla.push(2);
assert_no_alloc(|| {
drop(bla);
});
drop(_receiver);
}

// Don't execute this in CI. It crashes the test process which counts as "not passed".
#[test]
#[ignore]
#[should_panic]
fn abort_on_allocate() {
init();
let _receiver = init();
assert_no_alloc(|| {
let mut bla: Vec<i32> = vec![];
bla.push(2);
Expand Down
1 change: 0 additions & 1 deletion base/src/metrics_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::mpsc::{Receiver, SyncSender};
use std::sync::OnceLock;
use std::thread;
use std::thread::JoinHandle;
use std::time::{Duration, Instant};

/// This will contain the metrics sender for async metrics recording if metrics are enabled.
Expand Down
6 changes: 3 additions & 3 deletions dialogs/src/header_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ pub fn create(context: ScopedContext, ids: &mut IdGenerator) -> Dialog {
styles: Styles(vec![DS_SETFONT, DS_CONTROL, WS_CHILD, WS_VISIBLE]),
controls: upper_part_controls
.into_iter()
.chain(show_controls.into_iter())
.chain(lower_part_controls.into_iter())
.chain(divider_controls.into_iter())
.chain(show_controls)
.chain(lower_part_controls)
.chain(divider_controls)
.collect(),
..context.default_dialog()
}
Expand Down
8 changes: 4 additions & 4 deletions dialogs/src/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,10 @@ pub fn create(context: ScopedContext, ids: &mut IdGenerator) -> Dialog {
]),
controls: mapping_controls
.into_iter()
.chain(source_controls.into_iter())
.chain(target_controls.into_iter())
.chain(glue_controls.into_iter())
.chain(footer_controls.into_iter())
.chain(source_controls)
.chain(target_controls)
.chain(glue_controls)
.chain(footer_controls)
.collect(),
..context.default_dialog()
}
Expand Down
12 changes: 5 additions & 7 deletions main/src/application/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Session {
global_osc_feedback_task_sender: &'static SenderToNormalThread<OscFeedbackTask>,
control_surface_main_task_sender: &'static RealearnControlSurfaceMainTaskSender,
) -> Session {
let session = Self {
Self {
// As long not changed (by loading a preset or manually changing session ID), the
// session ID is equal to the instance ID.
id: prop(instance_id.to_string()),
Expand Down Expand Up @@ -332,8 +332,7 @@ impl Session {
instance_track_descriptor: Default::default(),
instance_fx_descriptor: session_defaults::INSTANCE_FX_DESCRIPTOR,
memorized_main_compartment: None,
};
session
}
}

pub fn instance_id(&self) -> &InstanceId {
Expand Down Expand Up @@ -2105,7 +2104,7 @@ impl Session {
Compartment::Controller => &mut self.default_controller_group,
};
default_group.replace(model.default_group);
self.set_groups_without_notification(compartment, model.groups.into_iter());
self.set_groups_without_notification(compartment, model.groups);
self.set_mappings_without_notification(compartment, model.mappings);
let compartment_params = self.params.compartment_params_mut(compartment);
compartment_params.reset_all();
Expand Down Expand Up @@ -2676,9 +2675,8 @@ impl DomainEventHandler for WeakSession {
included_target_types: &included_targets,
touch_cause: m.touch_cause.unwrap_or_default(),
};
let Some(target) =
BackboneState::get().find_last_touched_target(filter) else
{
let Some(target) = BackboneState::get().find_last_touched_target(filter)
else {
return Ok(());
};
let Some(m) = s.find_mapping_by_qualified_id(id).cloned() else {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/conditional_activation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl EelCondition {
}

fn extract_used_param_indexes(eel_script: &str) -> HashSet<u32> {
let param_regex = regex!(r#"\bp([0-9]+)\b"#);
let param_regex = regex!(r"\bp([0-9]+)\b");
param_regex
.captures_iter(eel_script)
.flat_map(|m| m[1].parse())
Expand Down
6 changes: 1 addition & 5 deletions main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,7 @@ impl MainMapping {
self.activation_condition_1
.target_value_lead_mapping()
.into_iter()
.chain(
self.activation_condition_2
.target_value_lead_mapping()
.into_iter(),
)
.chain(self.activation_condition_2.target_value_lead_mapping())
}

pub fn update_activation_from_effect(
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/monitoring_fx_chain_change_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn diff(
} else {
None
};
Either::Left(opened_closed.into_iter().chain(enabled.into_iter()))
Either::Left(opened_closed.into_iter().chain(enabled))
} else {
Either::Right(iter::empty())
}
Expand Down
4 changes: 0 additions & 4 deletions main/src/infrastructure/data/license_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ use anyhow::{anyhow, Context};
use helgoboss_license_api::persistence::{LicenseData, LicenseKey};
use helgoboss_license_api::runtime::License;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::fs;
use std::path::PathBuf;
use std::rc::Rc;

pub type SharedLicenseManager = Rc<RefCell<LicenseManager>>;

#[derive(Debug)]
pub struct LicenseManager {
Expand Down
2 changes: 1 addition & 1 deletion main/src/infrastructure/data/target_model_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ impl TargetModelData {
TrackMonitoringMode,
AutomationModeOverride,
];
HashSet::from_iter(old_kinds.into_iter())
HashSet::from_iter(old_kinds)
});
model.change(C::SetLearnableTargetKinds(target_kinds));
model.change(C::SetTouchCause(self.touch_cause));
Expand Down
1 change: 0 additions & 1 deletion main/src/infrastructure/plugin/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use base::metrics_util::record_occurrence;
use helgoboss_allocator::{AsyncDeallocationIntegration, Deallocate, HelgobossAllocator};
use reaper_high::Reaper;
use std::alloc::{GlobalAlloc, Layout, System};

#[global_allocator]
Expand Down
49 changes: 14 additions & 35 deletions main/src/infrastructure/plugin/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ use crate::infrastructure::data::{
FileBasedPresetLinkManager, OscDevice, OscDeviceManager, SharedControllerPresetManager,
SharedMainPresetManager, SharedOscDeviceManager, SharedPresetLinkManager,
};
use crate::infrastructure::plugin::debug_util;
use crate::infrastructure::server;
use crate::infrastructure::server::{
MetricsReporter, RealearnServer, SharedRealearnServer, COMPANION_WEB_APP_URL,
};
use crate::infrastructure::ui::{MainPanel, MessagePanel};
use base::default_util::is_default;
use base::{
make_available_globally_in_main_thread_on_demand, metrics_util, Global, NamedChannelSender,
make_available_globally_in_main_thread_on_demand, Global, NamedChannelSender,
SenderToNormalThread, SenderToRealTimeThread,
};
use enum_iterator::IntoEnumIterator;
Expand All @@ -40,15 +39,14 @@ use crate::infrastructure::plugin::debug_util::resolve_symbols_from_clipboard;
use crate::infrastructure::plugin::tracing_util::TracingHook;
use crate::infrastructure::server::services::RealearnServices;
use crate::infrastructure::test::run_test;
use base::metrics_util::{metrics_are_enabled, record_duration_internal, MetricsHook};
use base::metrics_util::MetricsHook;
use helgoboss_allocator::{start_async_deallocation_thread, AsyncDeallocatorCommandReceiver};
use once_cell::sync::Lazy;
use realearn_api::persistence::{
Envelope, FxChainDescriptor, FxDescriptor, TargetTouchCause, TrackDescriptor, TrackFxChain,
};
use reaper_high::{
ActionKind, CrashInfo, Fx, Guid, MiddlewareControlSurface, Project, Reaper, RegisteredAction,
Track,
ActionKind, CrashInfo, Fx, Guid, MiddlewareControlSurface, Project, Reaper, Track,
};
use reaper_low::{PluginContext, Swell};
use reaper_medium::{
Expand All @@ -65,12 +63,9 @@ use std::collections::HashSet;
use std::fs;
use std::path::{Path, PathBuf};
use std::rc::{Rc, Weak};
use std::sync::mpsc;
use std::thread::JoinHandle;
use std::time::Duration;
use swell_ui::{SharedView, View, ViewManager, Window};
use tempfile::TempDir;
use tracing_subscriber::{EnvFilter, Layer};
use url::Url;

/// Queue size for sending feedback tasks to audio hook.
Expand Down Expand Up @@ -102,11 +97,11 @@ pub type RealearnControlSurface =

#[derive(Debug)]
pub struct App {
tracing_hook: Option<TracingHook>,
metrics_hook: Option<MetricsHook>,
/// RAII
_tracing_hook: Option<TracingHook>,
/// RAII
_metrics_hook: Option<MetricsHook>,
state: RefCell<AppState>,
#[cfg(feature = "playtime")]
license_manager: crate::infrastructure::data::SharedLicenseManager,
controller_preset_manager: SharedControllerPresetManager,
main_preset_manager: SharedMainPresetManager,
preset_link_manager: SharedPresetLinkManager,
Expand Down Expand Up @@ -155,19 +150,6 @@ enum AppState {
Suspended,
}

#[derive(Debug)]
struct UninitializedState {
control_surface_main_task_receiver:
crossbeam_channel::Receiver<RealearnControlSurfaceMainTask<WeakSession>>,
#[cfg(feature = "playtime")]
clip_matrix_event_receiver:
crossbeam_channel::Receiver<crate::domain::QualifiedClipMatrixEvent>,
additional_feedback_event_receiver: crossbeam_channel::Receiver<AdditionalFeedbackEvent>,
instance_orchestration_event_receiver: crossbeam_channel::Receiver<InstanceOrchestrationEvent>,
normal_audio_hook_task_receiver: crossbeam_channel::Receiver<NormalAudioHookTask>,
feedback_audio_hook_task_receiver: crossbeam_channel::Receiver<FeedbackAudioHookTask>,
}

#[derive(Debug)]
struct SleepingState {
control_surface: Box<RealearnControlSurface>,
Expand Down Expand Up @@ -249,7 +231,7 @@ impl App {
),
);
#[cfg(feature = "playtime")]
let license_manager = Self::init_clip_engine();
Self::init_clip_engine();
let backbone_state = BackboneState::new(
additional_feedback_event_sender.clone(),
RealearnTargetState::new(additional_feedback_event_sender.clone()),
Expand Down Expand Up @@ -307,11 +289,9 @@ impl App {
async_deallocation_receiver,
};
App {
tracing_hook,
metrics_hook,
_tracing_hook: tracing_hook,
_metrics_hook: metrics_hook,
state: RefCell::new(AppState::Sleeping(sleeping_state)),
#[cfg(feature = "playtime")]
license_manager: Rc::new(RefCell::new(license_manager)),
controller_preset_manager: Rc::new(RefCell::new(controller_preset_manager)),
main_preset_manager: Rc::new(RefCell::new(main_preset_manager)),
preset_link_manager: Rc::new(RefCell::new(preset_link_manager)),
Expand Down Expand Up @@ -378,19 +358,19 @@ impl App {
}

#[cfg(feature = "playtime")]
fn init_clip_engine() -> crate::infrastructure::data::LicenseManager {
fn init_clip_engine() {
let license_manager = crate::infrastructure::data::LicenseManager::new(
App::helgoboss_resource_dir_path().join("licensing.json"),
);
#[derive(Debug)]
struct RealearnMetricsRecorder;
impl playtime_clip_engine::MetricsRecorder for RealearnMetricsRecorder {
fn record_duration(&self, id: &'static str, delta: Duration) {
record_duration_internal(id, delta);
fn record_duration(&self, id: &'static str, delta: std::time::Duration) {
base::metrics_util::record_duration_internal(id, delta);
}
}
let metrics_recorder: Option<playtime_clip_engine::StaticMetricsRecorder> =
if metrics_are_enabled() {
if base::metrics_util::metrics_are_enabled() {
Some(&RealearnMetricsRecorder)
} else {
None
Expand All @@ -401,7 +381,6 @@ impl App {
metrics_recorder,
};
playtime_clip_engine::ClipEngine::get().init(args);
license_manager
}

fn reconnect_osc_devices(&self) {
Expand Down
2 changes: 1 addition & 1 deletion main/src/infrastructure/plugin/debug_util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::infrastructure::ui::get_text_from_clipboard;
use reaper_high::{resolve_symbols_from_text, ActionKind, Reaper};
use reaper_high::resolve_symbols_from_text;

pub fn resolve_symbols_from_clipboard() -> Result<(), Box<dyn std::error::Error>> {
let text = get_text_from_clipboard().ok_or("Couldn't read from clipboard.")?;
Expand Down
3 changes: 1 addition & 2 deletions main/src/infrastructure/plugin/tracing_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use reaper_high::Reaper;
use std::fmt::Arguments;
use std::io::{IoSlice, Write};
use std::sync::mpsc::{Receiver, Sender};
use std::thread::JoinHandle;
use std::{mem, thread};
use tracing_subscriber::{EnvFilter, FmtSubscriber, Layer};
use tracing_subscriber::{EnvFilter, FmtSubscriber};

#[derive(Debug)]
pub struct TracingHook {
Expand Down
Loading

0 comments on commit 1b17f00

Please sign in to comment.