Skip to content

Commit

Permalink
Add missing StoreMessageAndData, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
arnauds5 committed Jun 30, 2024
1 parent a0736a9 commit cf8dd55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ func (h *Handler) handleChallenge(msg mmessage.Message, channelPath string,
federationExpect.LaoId, federationExpect.ServerAddress)

if h.subs.HasChannel(remoteChannel) {
_ = h.db.StoreMessageAndData(channelPath, resultMsg)

// If the server was already sync, no need to add a goroutine
return h.subs.BroadcastToAllClients(msg, channelPath)
}
Expand Down Expand Up @@ -465,13 +467,10 @@ func (h *Handler) handleResult(msg mmessage.Message, channelPath string) error {
return err
}

err = h.db.StoreMessageAndData(channelPath, msg)
if err != nil {
return err
}

remoteLaoChannel := fmt.Sprintf("/root/%s", federationInit.LaoId)
if h.subs.HasChannel(remoteLaoChannel) {
_ = h.db.StoreMessageAndData(channelPath, msg)

// If the server was already sync, no need to add a goroutine
return h.subs.BroadcastToAllClients(msg, channelPath)
}
Expand All @@ -480,6 +479,8 @@ func (h *Handler) handleResult(msg mmessage.Message, channelPath string) error {
// wait until the remote channel is available to be subscribed on
h.waitSyncOrTimeout(remoteLaoChannel, time.Second*30)

_ = h.db.StoreMessageAndData(channelPath, msg)

_ = h.subs.BroadcastToAllClients(msg, channelPath)
}()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,15 @@ func Test_handleFederationChallenge(t *testing.T) {
laoID := "lsWUv1bKBQ0t1DqWZTFwb0nhLsP_EtfGoXHny4hsrwA="
laoID2 := "OWY4NmQwODE4ODRjN2Q2NTlhMmZlYWEwYzU1YWQwMQ=="
laoPath := fmt.Sprintf("/root/%s", laoID)
laoPath2 := fmt.Sprintf("/root/%s", laoID2)
channelPath := fmt.Sprintf("/root/%s/federation", laoID)
channelPath2 := fmt.Sprintf("/root/%s/federation", laoID2)

err = subs.AddChannel(laoPath)
require.NoError(t, err)
err = subs.AddChannel(laoPath2)
require.NoError(t, err)

err = subs.AddChannel(channelPath)
require.NoError(t, err)
err = subs.AddChannel(channelPath2)
Expand Down Expand Up @@ -812,6 +818,9 @@ func Test_handleFederationResult(t *testing.T) {
laoPath := fmt.Sprintf("/root/%s", laoID)
channelPath := fmt.Sprintf("/root/%s/federation", laoID)

err = subs.AddChannel(laoPath)
require.NoError(t, err)

err = subs.AddChannel(channelPath)
require.NoError(t, err)

Expand Down

0 comments on commit cf8dd55

Please sign in to comment.