2

I'm writing a framework to test the behaviour of the CernVM FS. Basically, I have a service that mounts a remote filesystem served over http and does it with automount as soon as the the user attempts to access to the configured mounting point.

One of the tests that I have to write, consists on checking if cvmfs respects the timeout configuration for dns request. So, I have a dns set to wait 180 seconds, but the service has to stop to try to mount the folder after 10 seconds if a proxy is used, after 5 seconds if the connection is direct.

I already have three test defined (one with a good dns, other two with a sleeping dns with and without proxy). All tests are successful (so, actually it fails when dns is sleeping), but I don't know how to check how long Perl opendir command waits before stating that it can't access the folder.

How can I measure this time? I know that it has to fail, but I want to be sure that it fails after 10 or 5 seconds (depending on configuration).

I have to do it in Perl, but any suggestion would be appreciated.

Zagorax
  • 11,440
  • 8
  • 44
  • 56

1 Answers1

1

You might measure the time between issuing the opendir and its return (successfully or unsuccessfully); something like:

use Carp;
use Time::HiRes qw(gettimeofday tv_interval);
my $dir   = '.' #...whatever...'
my $start = [gettimeofday];
opendir my $dfh, $dir or carp "opendir() failed: $!\n";
my $end   = [gettimeofday];
my $delta = tv_interval $start, $end;
print "opendir() took $delta seconds\n";
JRFerguson
  • 7,426
  • 2
  • 32
  • 36