Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestScheduler seems to use bogus values for frameTimeFactor #2475

Closed
memelet opened this issue Mar 17, 2017 · 7 comments
Closed

TestScheduler seems to use bogus values for frameTimeFactor #2475

memelet opened this issue Mar 17, 2017 · 7 comments

Comments

@memelet
Copy link

memelet commented Mar 17, 2017

RxJS version:
5.2.0

The value frameTimeFactor seems to be a static on VirtualTimeScheduler and used in some places in TestScheduler.

In some places its used as a static, TestScheduler.ts:35

    return indexOf * TestScheduler.frameTimeFactor;

But in others its used on this when there is no `this:

TestScheduler.ts:149

      const frame = i * this.frameTimeFactor;

TestScheduler.ts:199

    const frameOffset = subIndex === -1 ? 0 : (subIndex * -this.frameTimeFactor);

TestScheduler.ts:212

      const frame = i * this.frameTimeFactor + frameOffset;

Changing this.frameTimeFactor to TestScheduler.frameTimeFactor seems to fully allow for adjusting the resolution of time intervals. I believe there is a issue to that as part of testing improvements, but this is an easy fix standalone.

@CrazyBS
Copy link

CrazyBS commented Apr 16, 2017

I agree with this request. In order to fully control the time factors and max frames, I need to either ensure all time is overridable to 10ms increments or extend VirtualTimeScheduler myself and not use TestScheduler for testing. I have retry logic that waits several seconds that I'd like to test without injecting new delays into the source code.

@jayphelps
Copy link
Member

jayphelps commented May 24, 2017

this.frameTimeFactor is the same as TestScheduler.frameTimeFactor in the source.

class TestScheduler {
    static frameTimeFactor = 1;
    static kickDog() {
        return this.frameTimeFactor;
    }
}

// compiles to

var TestScheduler = (function () {
    function TestScheduler() {
    }
    TestScheduler.kickDog = function () {
        return this.frameTimeFactor;
    };
    return TestScheduler;
}());
TestScheduler.frameTimeFactor = 1;

In TS and JS, classes are objects themselves (not just the instances of those classes) so when calling a function (aka method in this case), this will refer to the object in which the function was called on.

TestScheduler.kickDog() is the same as TestScheduler.kickDog.call(TestScheduler), so TestScheduler is the context, used as this.


Are you actually seeing cases where this.frameTimeFactor is erroring out with Cannot read property 'frameTimeFactor' of undefined?

@jayphelps
Copy link
Member

You might also like https://www.npmjs.com/package/@kwonoj/rxjs-testscheduler-compat which was made by one of the core team members to experiment with bringing a similar api as v4 back to v5

@patrickkunka
Copy link

patrickkunka commented Feb 27, 2018

Regarding @CrazyBS comment about fully controlling frameTimeFactor, I'd also like to be able do this.

Say I have a stream with .throttleTime() applied, which throttles a provided input stream so that it emits only every 20 seconds (the 20s duration is arbitrary, and is provided externally).

I'd like to test it with a marble diagram like the following, where each dash represents 5000ms instead of the default 10ms:

IN:  -a-b-c-d-
OUT: -a---c---

I feel like this would be possible if I could override frameTimeFactor to equal 5000, on a TestSchedular instance basis (which I then provide to throttleTime()), but because it is static I can not.

Does this make sense as a feature request, or am I missing an easier way to do this?

@kwonoj
Copy link
Member

kwonoj commented Feb 27, 2018

#3231 and #3314 tracking this.

@patrickkunka
Copy link

@kwonoj fantastic, thanks!

@benlesh
Copy link
Member

benlesh commented Aug 18, 2020

This is resolved with TestScheduler "run mode". https://rxjs.dev/guide/testing/marble-testing

@benlesh benlesh closed this as completed Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants