Skip to content

chore: auto-open resources#1245

Merged
RangerMauve merged 2 commits intofeat/no-random-access-storage-in-testsfrom
feat/no-open-lifecycle
Mar 16, 2026
Merged

chore: auto-open resources#1245
RangerMauve merged 2 commits intofeat/no-random-access-storage-in-testsfrom
feat/no-open-lifecycle

Conversation

@gmaclennan
Copy link
Copy Markdown
Member

@gmaclennan gmaclennan commented Mar 16, 2026

This removes some of the changes in #1232 around resource opening. Putting initialization in _open() creates an additional state to manage for classes, "initialized but not open", and the need to wrap some functions and methods in a this.ready() guard, and a condition for a future dev "you must sometimes wait this.ready() before you access some properties". For example, #1232 was missing guards for BlobStore.get(), createReadStream(), createEntriesReadStream(). This isn't currently well covered in the tests because most/all reads happen after opening and writing resources - we're lacking tests that initialize a new instance with existing data and immediately try to read it.

There's no need for the async open setup anyway. All of the upstream hypercore modules wrap their ready state, so that you can call any method before they are ready. The CoMapeo Core code has an intentional architecture that removes the need to access hypercore properties that are not populated until after ready() e.g. core.key.

This adds a — currently unnecessary — call to this.ready().noop() in the constructor of all classes that use ReadyResource. I've done this because not all of our methods call this.ready() first so we don't guarantee a lazy init, but it works, for now, because the upstream holepunch modules either lazy-init or auto-open. I think it's safer to have a "init in constructor" pattern rather than try to implement lazy init, because lazy init opens too many opportunities for bugs down the line with little gain.

@gmaclennan
Copy link
Copy Markdown
Member Author

Now that tests are using random-access-file, they are running much slower than with random-access-memory, and occasionally run more than 10 mins, which was our previous CI timeout value. This PR also increases the CI timeout to 15 minutes.

@RangerMauve RangerMauve merged commit 2f0cad7 into feat/no-random-access-storage-in-tests Mar 16, 2026
11 checks passed
@RangerMauve RangerMauve deleted the feat/no-open-lifecycle branch March 16, 2026 17:06
RangerMauve added a commit that referenced this pull request Mar 16, 2026
* feat: Remove fast test option from test-e2e

* feat: Remove random-access-storage from more test-e2e

* test: Temporarily disable Consistent storage folders test

* test: Remove RAM from server test

* test: Remove RAM from coreManager in tests

* fix: Close blobstore correctly

* feat: Add ready-resource as dependency + types

* chore: Revert ready-resource to 1.0.0

* fix: Use ready-resource when loading/closing async resources

* chore: Fix ts in test-e2e/members.js

* test: Wait for blobStore to be ready for blob-api tests

* fix: Race conditions in core manager tests

* chore: make replicate async to fix race conditions

* test: update datastore test with new timings

* fix: wait for project ready when loading

* test: add create-core test utility

* chore: auto-open resources (#1245)

* chore: auto-open resources

* chore: increase CI timeout

* Update types/ready-resource.d.ts

Co-authored-by: Andrew Chou <andrewchou@fastmail.com>

* chore: re-add consistent folder name test

* fix: Only _close should be abstract in ready-resource

---------

Co-authored-by: Mauve Signweaver <contact@mauve.moe>
Co-authored-by: Gregor MacLennan <gmaclennan@awana.digital>
Co-authored-by: Andrew Chou <andrewchou@fastmail.com>
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

Successfully merging this pull request may close these issues.

2 participants