Conversation
...and the need to even have one at all
For some reason the unit tests stopped working for me today w/o this
...so it doesn't pollute other tests
Use lambdas & remove unnecessary asyncs
|
We found some additional isolation work is needed from config / data in the home directory. |
The prior approach broke the ability to specify a subset of tests on the command line
It's pretty flaky, but we're working on it
The before hook is failing pretty often
Ethan-Arrowood
left a comment
There was a problem hiding this comment.
Everything looks great. One code nit pick and a necessary change in the package.json scripts. nice work!
unitTests/testUtils.ts
Outdated
There was a problem hiding this comment.
Not sure how many tables there'd be but you can make this significantly faster by doing:
| for (const Table of envs) { | |
| try { | |
| await Table.delete(); | |
| // eslint-disable-next-line no-empty | |
| } catch (err) {} | |
| } | |
| await Promise.all(envs.map(table => table.delete())).catch(); |
There was a problem hiding this comment.
This is old code from the other repo's test_utils.js so I just copied it over. But sounds like a good change 👍🏻
package.json
Outdated
There was a problem hiding this comment.
Remove this.
The point of splitting test:unit and test:unit:all is so that you can run npm run test:unit <specific-unit-test-path> in order to run a singular test file. The test:unit:all passes in the unitTests directory to test:unit so you can run all the unit tests.
There was a problem hiding this comment.
Hmm... so now with this change running npm run test:unit gives you an error that there are no tests. I wasn't aware that test:unit:all was added so this was surprising and seemed broken. But this is all pretty new so no big deal and now I know. I do wish there were a reasonable way to output a more helpful error message, or even just have this default to "all" when nothing is specified, but I can't think of one.
There was a problem hiding this comment.
Agreed; I wish there was a better default or something. I couldn't think of a reasonable solution either that didn't involve like executing it via a mini cli script.
| maxHeaderSize: env.get(terms.CONFIG_PARAMS.HTTP_MAXHEADERSIZE), | ||
| }; | ||
| if (keepAliveTimeout) { | ||
| options['keepAliveTimeout'] = Number(keepAliveTimeout); |
There was a problem hiding this comment.
eslint lets you get away with using strings in brackets here? Why?
There was a problem hiding this comment.
Should it not? IIRC I did this instead of actually specifying an interface for the options. But I can certainly go back and do that instead.
There was a problem hiding this comment.
This is a workaround for violating TypeScript types? TIL!
kriszyp
left a comment
There was a problem hiding this comment.
Why are we converting unit tests to TypeScript? If we want our code to be used by TypeScript and JavaScript, isn't JavaScript the broader language that would provide better unit testing coverage?
kriszyp
left a comment
There was a problem hiding this comment.
I thought we had been using a convention of module-test.js for test names. Where did we decide to change this?
I wasn't aware we had a convention, and had already run into both the one I used here and the one you describe in the tests that had been brought over from the old repo. I ran across something that said I was planning to write up some conventions for tests in this repo (in a contributing doc or similar), but it sounds like there are some already written up I need to (re-)familiarize myself with. Do you have a link? |
| * | ||
| * - WSM 2025-10-31 | ||
| */ | ||
| describe.skip('Types Validation', () => { |
There was a problem hiding this comment.
Do we have a follow-up ticket for this? This seemed to be a pretty reliable test before.
There was a problem hiding this comment.
I'll create it along with others for the other skipped tests.
| function getHomeDir() { | ||
| let homeDir = undefined; | ||
| // for hermetic tests | ||
| if (process.env.OVERRIDE_HOME_DIR) { |
There was a problem hiding this comment.
Does this function differently than process.env.ROOTPATH?
There was a problem hiding this comment.
Does this function differently than
process.env.ROOTPATH?
Yes, but that seems to work just as well in its place, so I'll issue a followup PR that switches over. Thanks!
| maxHeaderSize: env.get(terms.CONFIG_PARAMS.HTTP_MAXHEADERSIZE), | ||
| }; | ||
| if (keepAliveTimeout) { | ||
| options['keepAliveTimeout'] = Number(keepAliveTimeout); |
There was a problem hiding this comment.
This is a workaround for violating TypeScript types? TIL!
I think having them be TypeScript gives us (optional) tools to improve the quality of our tests just like it does for the code itself. And I have a hard time imaging test code that passes in TS but would allow a valid JS equivalent to fail (it's entirely possible that this is a failure of my imagination, however!). I'd be curious to hear what others in the community think about this, though. It also allows us to use the |
https://github.com/HarperFast/harperdb/tree/main/unitTests has hundred(s?) of test cases with module-test.js naming convention. |
But perhaps you're thinking of valid JS code that isn't valid TS code that we'd want to test for expected behavior? I guess we'd either have to sprinkle around directives to expect TS errors here and there in some test code, or, like you said, keep the tests written in JS. I think I prefer the former, but it's not a strongly-held opinion. Again I would love to hear what others think here. |
That's true and fair. I had started with bringing over the I am happy to use either convention, though! |
|
I don't see how this properly going to track with cherry-picking, since the tests were copied in with different names and there is no rename history. I think this PR needs to be reverted and submitting again with direct filename preservation (like unitTests/resources/blob-test.js), so we properly keep our repositories in sync. |
Makes sense. Maybe if we decide on a naming convention (because there would already be two different ones in here with just these two categories of unit tests), we could bring the files in w/ their existing names, commit, rename, commit, and then adapt them to this repo? Thoughts, @Ethan-Arrowood? |
|
Yeah so git is actually pretty smart as long as you do the rename through a commit as you described Wes. Seeing some of Kris' comments now I think redoing this PR would be best. Since this was merged using a merge commit, adding many individual commits, I think we may just want to reset I'll confirm this procedure on today's standup call |
|
For public record: We confirmed on our eng call today to reset the main branch and redo this PR. I'll be completing this shortly and then posting about the |
This started as me just experimenting with how much work it would be to migrate the resources unit tests (😅). Pretty quickly I ran into issues of the tests not being hermetic; both with respect to each other and with respect to the broader system.
So I dove back down that rabbit hole, but this time I hit pay dirt.
These unit tests all pass by themselves and together, and don't care one lick what is or isn't in your home directory (at least the Harper-y stuff;
~/.harperdb,~/hdb, etc.).This PR introduces a new
unitTests/testUtils.tsmodule that defines two important functions:createTestSandbox- this creates an environment in which tables can be created and used, but does not need nor use any existing Harper installation; it should be called in abeforehook (or abeforeEachif you find it really necessary)cleanupTestSandbox- this cleans up after createTestSandbox and should be called in theafterhook (orafterEachif you are callingcreateTestSandboxinbeforeEach). This one is async, so if it isn't the only thing you're passing to the hook (e.g.after(cleanupTestSandbox);), be sure toawaitit so it finishes its job before other tests are run.