kcott has asked for the wisdom of the Perl Monks concerning the following question:
I'm extending an application for $work and am seeking some advice on testing unexpected I/O failures.
The application receives a lot of parameters and I perform sanity checks on these. There are three parameters of interest with respect to this SoPW, in brief:
The application works fine if good parameters are supplied. There's a total of nine (file-related) sanity checks; I've successfully tested all of these with bad parameters.
The actual I/O is very straightforward; e.g.
open my $in_fh, '<', $input_file_path ... open my $out_fh, '>', $output_file_path ...
The error messages on failure are similarly standard:
Can't open $input_file_path for reading: $! Can't open $output_file_path for writing: $!
Given the sanity checks, I/O failure would be unexpected but still possible; for instance, between the sanity checks and an open call, a file could be deleted or renamed, it's permissions changed, a hardware failure could occur, and so on.
I managed to test the write failure by running normally; manually removing the write permissions of the output file;
and then running again with the same parameters.
Yes, I remembered to put the write permissions back after this test. :-)
So that just leaves me with testing the read failure; unfortunately, I can't think of a way to do that. Any ideas would be greatly appreciated.
While I do like to test everything, if this last test can't be done it's not a huge problem. The code is very straightforward (I've probably written similar code thousands of times in the past); the syntax is fine (perl -c); and, I know it works with good parameters.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing unexpected I/O failures
by Fletch (Bishop) on Nov 24, 2020 at 05:26 UTC | |
by kcott (Archbishop) on Nov 24, 2020 at 20:05 UTC | |
by Fletch (Bishop) on Nov 25, 2020 at 14:31 UTC | |
|
Re: Testing unexpected I/O failures
by GrandFather (Saint) on Nov 24, 2020 at 03:25 UTC | |
by kcott (Archbishop) on Nov 24, 2020 at 04:27 UTC | |
by bliako (Abbot) on Nov 24, 2020 at 11:22 UTC | |
by kcott (Archbishop) on Nov 24, 2020 at 20:29 UTC | |
|
Re: Testing unexpected I/O failures
by jszinger (Scribe) on Nov 24, 2020 at 17:49 UTC | |
by kcott (Archbishop) on Nov 24, 2020 at 21:19 UTC | |
|
Re: Testing unexpected I/O failures
by Don Coyote (Hermit) on Nov 24, 2020 at 11:54 UTC | |
by kcott (Archbishop) on Nov 24, 2020 at 20:46 UTC |