Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging inside Actor with SyncContext is not captured by tests #414

Open
CrazyRoka opened this issue Aug 1, 2020 · 1 comment
Open

Logging inside Actor with SyncContext is not captured by tests #414

CrazyRoka opened this issue Aug 1, 2020 · 1 comment

Comments

@CrazyRoka
Copy link

I am writing Actix-Web application and using Actix for my service layer. During testing I am enabling logging with this piece of code:

static INIT: Once = Once::new();

pub fn initialize() {
    INIT.call_once(|| {
        dotenv::from_filename("test.env").ok();
        let _ = pretty_env_logger::formatted_builder()
            .parse_filters(&var("RUST_LOG").unwrap())
            .is_test(true)
            .init();
    });
}

Logs are captured during testing and are printed in failed test stdout. Great!
But recently I started using SyncContext in Actix and logs appeared during the tests. I can't disable them. It seems like SyncArbiter is spawning threads that are not configured to print logs to stdout. Do you know how I can disable logs during testing and enable them in failed tests?

I am logging with pretty_env_logger and log crates. Maybe, there is a better solution for doing so?
rustc version 1.45.1
actix version 0.9.0
log version 0.4.11
pretty_env_logger version 0.4.0

@CrazyRoka
Copy link
Author

Fixed issue with this code

impl Actor for DbExecutor {
    #[cfg(not(test))]
    type Context = actix::SyncContext<Self>;
    #[cfg(test)]
    type Context = actix::Context<Self>;
}

I think there should be better way to do so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant