Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add $*CLOCK so we can mock it in S02-builtin_data_types/instants-and-durations.t #18

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

dwhipp commented Mar 3, 2011

Defined a role, POSIX-Clock that defines the basic ways that we interact with the system wallclock.
Defined a class, System-Clock, that delegates to time__n, time__I, and sleep__vN pir functions
Define $_CLOCK as the current instance of the clock
re-implemented term, term, and sleep to use $_CLOCK

With this change it will be trivial to mock the wallclock so that tests no longer defend on system time (and thus run faster, and are more reliable). For example, S02-builtin_data_types/instants-and-durations.t can add:

class Mock-Clock does POSIX-Clock {
has $.time is rw;
method time_as_real() { $.time }
method sleep($seconds) { $.time += $seconds }
}
$*CLOCK = Mock-Clock.new( :time(42.5) );

Owner

moritz commented Mar 4, 2011

I like the idea, but please name the coercion method just Real -- it is convention in Perl 6 to name coercion methods the same as the type they coerce to.

I also don't see the utility of the POSIX-Clock, which by itself would just loop infinitely by mutually recursive calls to time_as_real and time_as_int.

Finally I don't like the class names... maybe Clock::System and Clock::POSIX instead?

Contributor

dwhipp commented Mar 4, 2011

I'm not wedded to the current implementation, but:

To name the coercion method just "Real" (and, presumably, Int) would imply that it is the clock itself that it being coerced. Seems a little strange.

When you say that you don't see the utility of POSIX-Clock, do you mean that you don't see the need for a role, or just that the default implementations of the two "time-as" methods seems unnecessary. The reason for doing it that was was so that concrete clocks need to implement only one of the two methods. The only use-case for this is to use mocks in the test suite, so I could break the cycle and define .Real as {...}.

@scottp scottp pushed a commit to scottp/rakudo that referenced this pull request May 12, 2011

@pmichaud pmichaud Release #18 is no longer "planned" -- it "happened". masak++ 7032827

@pmichaud pmichaud closed this Aug 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment