solana-labs / solana

Web-Scale Blockchain for fast, secure, scalable, decentralized apps and marketplaces.
https://solanalabs.com
Apache License 2.0
13.19k stars 4.3k forks source link

Program test framework reaches timeout for some panics #17133

Open Arrowana opened 3 years ago

Arrowana commented 3 years ago

Problem

Setup

    let program_id = Pubkey::new_unique();
    let pt = ProgramTest::new(
        "some_program_that_is_going_to_explode",
        program_id,
        processor!(Processor::process),
    );

Let's say I do something stupid that will panic in the program

let mut token_infos = Vec::with_capacity(4);
for i in 0..4 {
    let account_info = next_account_info(account_info_iter)?;
    token_infos[i] = token_info;
}

The output is:

test test_stuff... test test_add_stuff has been running for over 60 seconds
test test_stuff ... FAILED

failures:

---- test_stuff stdout ----
thread 'solana-bank-forks-client' panicked at 'index out of bounds: the len is 0 but the index is 0', src/processor.rs:129:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'test_stuff' panicked at 'assertion failed: `Err(IoError(Custom { kind: TimedOut, error: "Client dropped expired request." }))` does not match `Ok(())`', tests/functional.rs:721:5

I waited 60 seconds to get this, most likely developer will assume it deadlocked way before that and kill the process (I did), losing all opportunity to understand what went wrong.

Proposed Solution

If something bad occurs in the program, the banks_client.process_transaction immediately returns and provides this useful backtrace

CriesofCarrots commented 2 years ago

@Arrowana , do you by chance still have code that exemplifies this issue? Want to test new BanksClient api that should fail fast. (edit) Nevermind! I ended up writing something

CriesofCarrots commented 2 years ago

@Arrowana , it looks to me like this is only a problem with cargo test (program loaded as native), and that cargo test-bpf does not exhibit this. Can you please confirm?

Arrowana commented 2 years ago

That was a long time ago, can't remember how to cause it. Yes, it seems like this was only happening for cargo test