Project

General

Profile

Actions

action #176823

closed

post_run_hook is not always executed despite documentation saying so size:S

Added by jbaier_cz 19 days ago. Updated 1 day ago.

Status:
Resolved
Priority:
Low
Assignee:
Category:
Regressions/Crashes
Target version:
Start date:
2025-02-09
Due date:
% Done:

0%

Estimated time:

Description

Observation

See documentation for post_run_hook(https://open.qa/docs/#_post_run_hook):

It is called after run() regardless of the result of the test run.

This is not correct. The hook will not run if the test fails, see reproducer where only post_fail_hook is executed.

Acceptance criteria

  • AC1: post_run_hook documentation matches the behavior

Suggestions

  • Either both hooks are executed or the documentation mentions that post_run_hook will not be called in some cases.
  • Investigate if this is expected behavior - apparently this has not changed recently
  • Check whether there was a reason for this. Maybe we actually want in case of a failure only the post_fail_hook. So perhaps it is best to just update the documentation (would be ok with @jbaier_cz who created the ticket for its own distri).
  • Related: #13868

Files

Actions #1

Updated by okurz 19 days ago

  • Tags set to reactive work
Actions #2

Updated by livdywan 15 days ago

  • Subject changed from post_run_hook is not always executed despite documentation saying so to post_run_hook is not always executed despite documentation saying so size:S
  • Description updated (diff)
  • Status changed from New to Workable
Actions #3

Updated by gpathak 9 days ago

  • Assignee set to gpathak
Actions #4

Updated by gpathak 8 days ago

  • Assignee deleted (gpathak)

Unassigning, since I am caught up with other task.

Actions #5

Updated by gpathak 7 days ago

  • Assignee set to gpathak
Actions #6

Updated by gpathak 4 days ago

  • Status changed from Workable to In Progress

Looking into reproducing the issue by writing a very minimal test.

Actions #7

Updated by jbaier_cz 4 days ago ยท Edited

Looking into reproducing the issue by writing a very minimal test.

The reproducer is linked in the description of this ticket, see https://openqa.opensuse.org/tests/4842740#step/reproducer/5 (and https://github.com/os-autoinst/os-autoinst-distri-openQA/blob/20c7e93e3f2ad1fd33d4fda2e4f6e67a8e318157/tests/reproducer.pm for the code)

Actions #8

Updated by gpathak 4 days ago

jbaier_cz wrote in #note-7:

Looking into reproducing the issue by writing a very minimal test.

The reproducer is linked in the description of this ticket, see https://openqa.opensuse.org/tests/4842740#step/reproducer/5 (and https://github.com/os-autoinst/os-autoinst-distri-openQA/blob/20c7e93e3f2ad1fd33d4fda2e4f6e67a8e318157/tests/reproducer.pm for the code)

Assets are missing, unable to clone the job.

Actions #9

Updated by jbaier_cz 4 days ago

gpathak wrote in #note-8:

Assets are missing, unable to clone the job.

That should be a problem, the reproducer is in a branch so you can always schedule a newer run. Here is it: https://openqa.opensuse.org/tests/4880482

(I just did openqa-clone-custom-git-refspec https://github.com/os-autoinst/os-autoinst-distri-openQA/tree/reproducer https://openqa.opensuse.org/tests/4880477)

Actions #10

Updated by jbaier_cz 4 days ago

jbaier_cz wrote in #note-9:

gpathak wrote in #note-8:

Assets are missing, unable to clone the job.

Correction (see https://suse.slack.com/archives/C02AJ1E568M/p1740406234200799 for context), this is the new test: https://openqa.opensuse.org/tests/4880517

Actions #11

Updated by gpathak 3 days ago

@jbaier_cz's observation about post_run_hook is right. post_run_hook even if present, doesn't execute in case of a failure encountered in run subroutine of a test. In case of a failure the post_fail_hook gets executed if present.

Updated by gpathak 3 days ago

gpathak wrote in #note-11:

@jbaier_cz's observation about post_run_hook is right. post_run_hook even if present, doesn't execute in case of a failure encountered in run subroutine of a test. In case of a failure the post_fail_hook gets executed if present.

I ran the reproducer from https://openqa.opensuse.org/tests/4880517 on my local setup and got exact same result.
I also did some modifications as well, I added some initial code from prepare.pm in reproducer.pm for setting up console and logging in as root user and removed zypper calls to reduce testing time.

use Mojo::Base 'openQAcoretest';
use utils qw(disable_packagekit switch_to_root_console);
use testapi;

sub run {
    switch_to_root_console;
    assert_screen 'inst-console';
    type_string "root\n";
    assert_screen 'password-prompt';
    type_password;
    send_key 'ret';
    wait_still_screen(2);
    assert_script_run("echo 'hello_world!'");
    assert_script_run("echo ''");
    #assert_script_run("/bin/false");
    enter_cmd "echo 'hello_world' > /dev/$serialdev";
    die "we could not see expected output" unless wait_serial "hello_world", 30;
}

sub post_run_hook {
    #record_info 'this will not run on test failure';
    force_soft_failure 'post_run_hook: this should be only a softfail';
}

sub post_fail_hook {
    force_soft_failure 'post_fail_hook: this should be only a softfail';
}

1;

This resulted in a soft failure from post_run_hook but in this case post_fail_hook wasn't called.

Used this command to trigger the test

openqa-cli api -X POST jobs HDD_1=opensuse-Tumbleweed-x86_64-20250223-minimalx@64bit.qcow2 MACHINE=64bit TEST=tests/install/boot,install/reproducer DISTRI=openqa EXCLUDE_MODULES=openqa_webui,openqa_worker,test_distribution,worker,start_test,test_running,dashboard,login,tests,search,shutdown,prepare

Modified post_run_hook to test if post_fail_hook is called when a failure is encountered in post_run_hook

sub post_run_hook {
    die "we could not see expected output" unless wait_serial "post_run_hook: this should fail and call post_fail_hook", 30;
}

sub post_fail_hook {
    force_soft_failure 'post_fail_hook: this should be only a softfail';
}



Actions #14

Updated by gpathak 1 day ago

  • Status changed from In Progress to Resolved
Actions

Also available in: Atom PDF