.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Test::Mock::Time 3pm" .TH Test::Mock::Time 3pm "2020-05-05" "perl v5.30.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::Mock::Time \- Deterministic time & timers for event loop tests .SH "VERSION" .IX Header "VERSION" This document describes Test::Mock::Time version v0.1.7 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Test::Mock::Time; \& \& # All these functions will return same constant time \& # until you manually move time forward by some deterministic \& # value by sleep(), ff() or doing one tick of your event loop. \& say time(); \& say localtime(); \& say gmtime(); \& say Time::HiRes::time(); \& say Time::HiRes::gettimeofday(); \& say Time::HiRes::clock_gettime(CLOCK_REALTIME()); \& say Time::HiRes::clock_gettime(CLOCK_MONOTONIC()); \& \& # All these functions will fast\-forward time (so time() etc. \& # will return increased value on next call) and return immediately. \& # Pending timers of your event loop (if any) will not be processed. \& sleep(1); \& Time::HiRes::sleep(0.5); \& Time::HiRes::usleep(500_000); \& Time::HiRes::nanosleep(500_000_000); \& Time::HiRes::clock_nanosleep(500_000_000); \& \& # This will fast\-forward time and process pending timers (if any). \& ff(0.5); \& \& # These will call ff() in case no other (usually I/O) event happens in \& # $Test::Mock::Time::WAIT_ONE_TICK seconds of real time and there are \& # some active timers. \& Mojo::IOLoop\->one_tick; \& EV::run(EV::RUN_ONCE); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module replaces actual time with simulated time everywhere (core \fBtime()\fR, Time::HiRes, \s-1EV,\s0 AnyEvent with \s-1EV,\s0 Mojolicious, X) and provide a way to write deterministic tests for event loop based applications with timers. .PP \&\fB\s-1IMPORTANT\s0!\fR This module \fBmust\fR be loaded by your script/app/test before other related modules (Time::HiRes, Mojolicious, \s-1EV,\s0 etc.). .SH "EXPORTS" .IX Header "EXPORTS" These functions are exported by default: .PP .Vb 1 \& ff .Ve .SH "INTERFACE" .IX Header "INTERFACE" .SS "\s-1WAIT_ONE_TICK\s0" .IX Subsection "WAIT_ONE_TICK" .Vb 1 \& $Test::Mock::Time::WAIT_ONE_TICK = 0.05; .Ve .PP This value is used to limit amount of real time spend waiting for non-timer (usually I/O) event while one tick of event loop if there are some active timers. In case no events happens while this time event loop will be interrupted and time will be fast-forward to time when next timer should expire by calling \fBff()\fR. .SS "ff" .IX Subsection "ff" .Vb 2 \& ff( $seconds ); \& ff(); .Ve .PP Fast-forward current time by \f(CW$seconds\fR (can be fractional). All functions like \fBtime()\fR will returns previous value increased by \f(CW$seconds\fR after that. .PP Will run callbacks for pending timers of your event loop if they'll expire while \f(CW$seconds\fR or if they've already expired (because you've used functions like \fBsleep()\fR which fast-forward time without processing timers). .PP When called without params will fast-forward time by amount needed to run callback for next pending timer (it may be 0 in case there are no pending timers or if next pending timer already expired). .SS "Mocked functions/methods from other modules" .IX Subsection "Mocked functions/methods from other modules" See \*(L"\s-1SYNOPSIS\*(R"\s0 for explanation how they works. .IP "\s-1CORE::GLOBAL\s0" 4 .IX Item "CORE::GLOBAL" .RS 4 .PD 0 .IP "time" 4 .IX Item "time" .IP "localtime" 4 .IX Item "localtime" .IP "gmtime" 4 .IX Item "gmtime" .IP "sleep" 4 .IX Item "sleep" .RE .RS 4 .RE .IP "Time::HiRes" 4 .IX Item "Time::HiRes" .RS 4 .IP "time" 4 .IX Item "time" .IP "gettimeofday" 4 .IX Item "gettimeofday" .IP "clock_gettime" 4 .IX Item "clock_gettime" .IP "clock_getres" 4 .IX Item "clock_getres" .IP "sleep" 4 .IX Item "sleep" .IP "usleep" 4 .IX Item "usleep" .IP "nanosleep" 4 .IX Item "nanosleep" .IP "clock_nanosleep" 4 .IX Item "clock_nanosleep" .RE .RS 4 .RE .IP "Mojo::Reactor::Poll" 4 .IX Item "Mojo::Reactor::Poll" .PD All required methods. .IP "\s-1EV\s0" 4 .IX Item "EV" All required methods except: .Sp .Vb 2 \& EV::once \& EV::Watcher::feed_event .Ve .SH "SUPPORT" .IX Header "SUPPORT" .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. .SS "Source Code" .IX Subsection "Source Code" This is open source software. The code repository is available for public review and contribution under the terms of the license. Feel free to fork the repository and submit pull requests. .PP .PP .Vb 1 \& git clone https://github.com/powerman/perl\-Test\-Mock\-Time.git .Ve .SS "Resources" .IX Subsection "Resources" .IP "\(bu" 4 MetaCPAN Search .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers Matrix .Sp .IP "\(bu" 4 \&\s-1CPANTS: A CPAN\s0 Testing Service (Kwalitee) .Sp .SH "AUTHOR" .IX Header "AUTHOR" Alex Efros .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2016\- by Alex Efros . .PP This is free software, licensed under: .PP .Vb 1 \& The MIT (X11) License .Ve