App-DubiousHTTP

 view release on metacpan or  search on metacpan

lib/App/DubiousHTTP/TestServer.pm  view on Meta::CPAN

	    return;
	}

	$clients{fileno($cl)}{time} = time();
	substr($wbuf[0],0,$n,'');
	if ($wbuf[0] eq '') {
	    shift @wbuf;
	    if (@wbuf) {
		# delay sending of next packet
		$SELECT->mask($cl,1,0);  # disable write
		$SELECT->timer($cl,1, sub { $write->($cl); });
		return;
	    }
	}
	goto handle_data;
    };

    $SELECT->handler($cl,0,$read,1,$write);
    $SELECT->mask($cl,0,1);
}

lib/App/DubiousHTTP/TestServer.pm  view on Meta::CPAN

}

package App::DubiousHTTP::TestServer::Select;
use Scalar::Util 'weaken';
use Time::HiRes 'gettimeofday';

my $maxfn = 0;
my @handler;
my @didit;
my @timeout;
my @timer;
my @mask = ('','');
my @tmpmask;
my $now = gettimeofday();
*_debug = \&App::DubiousHTTP::TestServer::_debug;

sub new { bless {},shift }
sub delete {
    my ($self,$cl) = @_;
    defined( my $fn = fileno($cl) ) or die "invalid fd";
    $DEBUG && _debug("remove fd $fn");
    vec($mask[0],$fn,1) = vec($mask[1],$fn,1) = 0;
    vec($tmpmask[0],$fn,1) = vec($tmpmask[1],$fn,1) = 0 if @tmpmask;
    $handler[$fn] = $didit[$fn] = $timeout[$fn] = $timer[$fn] = undef;
    if ($maxfn == $fn) {
	$maxfn-- while ($maxfn>=0 && !$handler[$maxfn]);
    }
}

sub handler {
    my ($self,$cl,%sub) = @_;
    defined( my $fn = fileno($cl) ) or die "invalid fd";
    $maxfn = $fn if $fn>$maxfn;
    weaken(my $wcl = $cl);
    while (my ($rw,$sub) = each %sub) {
	$sub = [ $sub ] if ref($sub) eq 'CODE';
	splice(@$sub,1,0,$wcl);
	$handler[$fn][$rw] = $sub;
	$DEBUG && _debug("add handler($fn,$rw)");
    }
}

sub timer {
    my ($self,$cl,$to,$cb) = @_;
    defined( my $fn = fileno($cl) ) or die "invalid fd";
    ($cb, my @arg) = ref($cb) eq 'CODE' ? ($cb):@$cb;
    push @{ $timer[$fn] }, [ $now+$to,$cb,@arg ];
    @{ $timer[$fn] } = sort { $a->[0] <=> $b->[0] } @{ $timer[$fn] };
}

sub timeout {
    my ($self,$cl,$to,$cb) = @_;
    defined( my $fn = fileno($cl) ) or die "invalid fd";
    if ($to) {
	($cb, my @arg) = ref($cb) eq 'CODE' ? ($cb):@$cb;
	$timeout[$fn] = [ $to,$cb,@arg ];
    } else {
	$timeout[$fn] = undef;

lib/App/DubiousHTTP/TestServer.pm  view on Meta::CPAN

	$didit[$fn] = $now if $val;
    }
}

sub loop {
    my $to;
    loop:

    $to = undef;
    for( my $fn=0;$fn<=$maxfn;$fn++ ) {
	$timer[$fn] or next;
	while (1) {
	    my $t = $timer[$fn][0];
	    if (!$t) {
		$timer[$fn] = undef;
		last;
	    }
	    my ($fire,$cb,@arg) = @$t;
	    if ($fire>$now) {
		# timer in future, update $to
		$to = $fire-$now if !$to || $fire-$now < $to;
		last;
	    }
	    # fire timer now
	    shift(@{$timer[$fn]});
	    $DEBUG && _debug("fire timer($fn)");
	    $cb->(@arg);
	}
    }

    for( my $fn=0;$fn<=$maxfn;$fn++ ) {
	defined $timeout[$fn] or next;
	vec($mask[0],$fn,1) or vec($mask[1],$fn,1) or next;
	my ($expire,$cb,@arg) = @{ $timeout[$fn] };
	my $diff = $didit[$fn] + $expire - $now;
	if ($diff>0) {

lib/App/DubiousHTTP/Tests.pm  view on Meta::CPAN

	    results = results + "I | " + status + " | " + test['page'] + " | " + test['desc'] + " | ok\n";
	}
    }
}


function set_success(xid,type) { check_nonxhr_result(xid, type, 'success') }
function set_fail(xid,type)    { check_nonxhr_result(xid, type, 'fail') }
function set_load(xid,type)    { check_nonxhr_result(xid, type) }

var nonxhr_timer;
var open_checks = {};
function check_nonxhr_result(xid,type,val) {
    _log( "xid:" + xid + ", type:" + type + ", val:" + val);
    if (!xid) {
	// final timeout done - mark remaining tests as timeout
	window.clearTimeout(nonxhr_timer);
	add_debug('*final timeout*');
	for(var k in open_checks) {
	    if (open_checks.hasOwnProperty(k)) {
		var test = open_checks[k];
		test['status'] = 'timeout';
		add_debug( "timeout: " + test['desc'], test);
		check_status_noevil(test);
	    }
	}
	runtests(); // submits final result
	return;
    }

    if (current_test && current_test['xid'] == xid) {
	window.clearTimeout(nonxhr_timer);
	test = current_test;
	if (val) {
	    add_debug( val + ": " + test['desc'], test);
	    test['status'] = val;
	    _removeElement(xid);
	    check_status_noevil(test);
	    if (fast_feedback && results.length > fast_feedback) {
		submit_part();
	    }
	} else if (!test['status']) {

lib/App/DubiousHTTP/Tests.pm  view on Meta::CPAN

		open = 1;
		break;
	    }
	}
	if (!open) {
	    runtests();
	    return;
	}

	// final timeout to wait for open_checks
	nonxhr_timer = window.setTimeout(
	    function() { check_nonxhr_result(); },
	    5000
	);
	return;
    }

    if (open_checks[xid]) {
	test = open_checks[xid];
	if (val) {
	    delete open_checks[xid];

lib/App/DubiousHTTP/Tests.pm  view on Meta::CPAN

    while (current_test = checks.shift()) {
	var total = checks.length + done;
	div_process.innerHTML = "Progress: " + (100*done/total).toFixed(1) + "% - " + current_test['desc'];
	if (current_test['html']) {
	    var html = current_test['html'];
	    if (typeof html == 'function') {
		html(div_work);
	    } else {
		div_work.innerHTML = html;
	    }
	    nonxhr_timer = window.setTimeout(
		function() { check_nonxhr_result(current_test['xid'],current_test['type'],'timeout'); },
		5000
	    );

	} else {
	    var page;
	    var what = current_test['retry'];
	    if (what) {
		current_test['file'] = null;
	    } else {



( run in 0.535 second using v1.01-cache-2.11-cpan-49f99fa48dc )