Compare commits

...

3 Commits

Author SHA1 Message Date
Guido D'Orsi
70437048fb Revert "Fix Error - 'ErrorLoadingCoValueCore'"
This reverts commit 0d43b2edbc.
2024-11-22 11:34:28 +01:00
Guido D'Orsi
72af643286 Revert "fix(coValueState): once a coValue is loaded send the known state to the rest of the peers"
This reverts commit a5559529ae.
2024-11-22 11:28:21 +01:00
Guido D'Orsi
35e2827bb7 Revert "Send empty known state on all states except available"
This reverts commit db5227b463.
2024-11-22 11:28:10 +01:00
3 changed files with 12 additions and 84 deletions

View File

@@ -703,7 +703,7 @@ function getDependedOnCoValues(
coValueRow?.header.ruleset.group,
...new Set(
newContentPieces.flatMap((piece) =>
Object.keys(piece.new)
Object.keys(piece)
.map((sessionID) =>
cojsonInternals.accountOrAgentIDfromSessionID(
sessionID as SessionID,

View File

@@ -264,19 +264,12 @@ async function loadCoValueFromPeers(
peers: PeerState[],
) {
for (const peer of peers) {
if (coValueEntry.state.type === "available") {
await peer.pushOutgoingMessage({
action: "load",
...coValueEntry.state.coValue.knownState(),
});
} else {
await peer.pushOutgoingMessage({
action: "load",
id: coValueEntry.id,
header: false,
sessions: {},
});
}
await peer.pushOutgoingMessage({
action: "load",
id: coValueEntry.id,
header: false,
sessions: {},
});
if (coValueEntry.state.type === "loading") {
await coValueEntry.state.waitForPeer(peer.id);

View File

@@ -24,7 +24,7 @@ describe("CoValueState", () => {
});
test("should create available state", async () => {
const mockCoValue = createMockCoValueCore(mockCoValueId);
const mockCoValue = { id: mockCoValueId } as CoValueCore;
const state = CoValueState.Available(mockCoValue);
expect(state.id).toBe(mockCoValueId);
@@ -34,7 +34,7 @@ describe("CoValueState", () => {
});
test("should handle found action", async () => {
const mockCoValue = createMockCoValueCore(mockCoValueId);
const mockCoValue = { id: mockCoValueId } as CoValueCore;
const state = CoValueState.Loading(mockCoValueId, ["peer1", "peer2"]);
const stateValuePromise = state.getCoValue();
@@ -232,7 +232,7 @@ describe("CoValueState", () => {
setTimeout(() => {
state.dispatch({
type: "available",
coValue: createMockCoValueCore(mockCoValueId),
coValue: { id: mockCoValueId } as CoValueCore,
});
}, 100);
}
@@ -285,7 +285,7 @@ describe("CoValueState", () => {
state.dispatch({
type: "available",
coValue: createMockCoValueCore(mockCoValueId),
coValue: { id: mockCoValueId } as CoValueCore,
});
await loadPromise;
@@ -311,7 +311,7 @@ describe("CoValueState", () => {
if (run > 2) {
state.dispatch({
type: "available",
coValue: createMockCoValueCore(mockCoValueId),
coValue: { id: mockCoValueId } as CoValueCore,
});
}
state.dispatch({
@@ -338,56 +338,6 @@ describe("CoValueState", () => {
vi.useRealTimers();
});
test("should start sending the known state to peers when available", async () => {
vi.useFakeTimers();
const mockCoValue = createMockCoValueCore(mockCoValueId);
const peer1 = createMockPeerState(
{
id: "peer1",
role: "storage",
},
async () => {
state.dispatch({
type: "available",
coValue: mockCoValue,
});
},
);
const peer2 = createMockPeerState(
{
id: "peer1",
role: "server",
},
async () => {
state.dispatch({
type: "not-found-in-peer",
peerId: "peer2",
});
},
);
const state = CoValueState.Unknown(mockCoValueId);
const loadPromise = state.loadFromPeers([peer1, peer2]);
for (let i = 0; i < CO_VALUE_LOADING_MAX_RETRIES; i++) {
await vi.runAllTimersAsync();
}
await loadPromise;
expect(peer1.pushOutgoingMessage).toHaveBeenCalledTimes(1);
expect(peer2.pushOutgoingMessage).toHaveBeenCalledTimes(1);
expect(peer2.pushOutgoingMessage).toHaveBeenCalledWith({
action: "load",
...mockCoValue.knownState(),
});
expect(state.state.type).toBe("available");
await expect(state.getCoValue()).resolves.toEqual({ id: mockCoValueId });
vi.useRealTimers();
});
});
function createMockPeerState(
@@ -410,18 +360,3 @@ function createMockPeerState(
return peerState;
}
function createMockCoValueCore(mockCoValueId: string) {
// Setting the knownState as part of the prototype to simplify
// the equality checks
const mockCoValue = Object.create({
knownState: vi.fn().mockReturnValue({
id: mockCoValueId,
header: true,
sessions: {},
}),
});
mockCoValue.id = mockCoValueId;
return mockCoValue as unknown as CoValueCore;
}