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

[fetch] Testing time-dependent results, disabling cache #35

Closed
gadicc opened this issue Feb 10, 2021 · 3 comments
Closed

[fetch] Testing time-dependent results, disabling cache #35

gadicc opened this issue Feb 10, 2021 · 3 comments

Comments

@gadicc
Copy link
Owner

gadicc commented Feb 10, 2021

Following on from #32, thanks @pudgereyem.

I'll add a way to disable using the cached result (probably an environment variable is easiest) but this still only solves half the problem. What we actually need is cached results from all the different possible times... a pain, I know -- but what we really want is for testing to really test everything, so we can be confident moving forward that EVERYTHING works all the time, without thinking that we need to run live tests at different times of the day.

@pudgereyem
Copy link
Contributor

Hey @gadicc, yes I think environment variable is the easiest as well.

Adding time to the cache string

Oh, I got an idea regarding how we can test different responses due to the time of day, and cache them as well. Currently our test files look something like this;

it(`passed validation for search: ${search}`, async () => {
    const devel = `search-${search}.json`;
    await yf.search(search, {}, { devel });
});

..which will create a cached response for the search here; tests/http/search-${search}.json.

However, since the response from Yahoo depends on the time of day, we could factor in "time of day" to the cache string. I think hourly would be enough. So we could do something like this;

const hourOfTheDay = new Date().getHours(); // e.g 10
const amOrPm = hourOfTheDay >= 12 ? 'pm' : 'am';
const timeString = `${hourOfTheDay}${amOrPm}`; // --> '10am'

it(`passed validation for search: ${search}`, async () => {
    const devel = `search-${search}-${timeString}.json`;
    await yf.search(search, {}, { devel });
});

If tests where then to be run it would create cached responses for all the 24 hours of the day, like so:

- tests/http/search-AAPL-1am.json
- tests/http/search-AAPL-2am.json
...

I think the solution could be more fleshed out and improved upon, e.g how do we best automate this. But it seems like a good start to me. What do you think @gadicc?

@gadicc
Copy link
Owner Author

gadicc commented Feb 10, 2021

Hey @pudgereyem, this is a good idea in terms of effort, as we don't really have to do much planning or thinking to cover everything. The downside though is that we already have 200 tests, which run fairly quickly, but to have 200 * 24 = 4800 tests, when almost all of them are near identical, I think is a bad trade off.

I think the best thing to do, even though it's a lot more effort, is to run specific timed tests for the different states of the markets, which we'll need to figure out (however, it will be great to add to our documentation too). So, a test specifically for an LSE stock when the LSE is in different states. I can't think of any other time related dependence beyond market state, can you?

Having said all that, I'm not even sure if there's that much work here... as all we have to do figure out is the different market state values and which fields are dependent on that. As an example, as a result of testing the new FETCH_DEVEL env variable (see commit afcb397 above or note in README), I've added all the preMarket*?: number stuff, and additional marketState enum values (in 1c256c7 above). Thanks of course for raising this issue in the first place as I only noticed this because of it!

But my suspicious is that there's not that much more to discover. I'll run the live tests at a few different times of the day (you're welcome to do so too if you want) and we'll see what other kinds of things come up, which should give us a better idea of what direction to go. So leaving open for now.

gadicc pushed a commit that referenced this issue Feb 10, 2021
# [1.7.0](v1.6.0...v1.7.0) (2021-02-10)

### Bug Fixes

* **index:** uhhhh s/_options/_opts/ like it's called everywhere else ([4492993](4492993))
* **moduleExec:** pass correct object to validation ([#27](#27)) ([8b0f9c7](8b0f9c7))
* **modules:** change overloading order specificy (fixes [#21](#21)) ([1806e61](1806e61))
* **quote:** extend marketState property ([0c36a60](0c36a60))
* **quote:** interface fixes, 10am UTC tests ([#35](#35)) ([1c256c7](1c256c7))

### Features

* new module recommendationsBySymbol ([#28](#28)) ([b467acb](b467acb))
@gadicc
Copy link
Owner Author

gadicc commented Feb 12, 2021

Going to close this since the FETCH_DEVEL=nocache code is done. Let's see what else comes up and then we'll decide on further strategy for time-dependent results.

@gadicc gadicc closed this as completed Feb 12, 2021
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

2 participants