Skip to content

Commit

Permalink
Add a test for 3ph disembargos, and fix some issues.
Browse files Browse the repository at this point in the history
Still fails because of the obvious panic("TODO..."), but caught a couple
unrelated bugs.
  • Loading branch information
zenhack committed Jun 29, 2023
1 parent 6816d38 commit 24b569a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
49 changes: 46 additions & 3 deletions rpc/3ph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type introTestInfo struct {
ProvideQID uint32
// question id for the call to CapArgsTest.call()
CallQID uint32
// export id for the promise which resolves to the third party cap
PromiseID uint32
// export id for the vine
VineID uint32
// export id for the cap returned from EmptyProvider.getEmpty()
Expand Down Expand Up @@ -196,8 +198,9 @@ func introTest(t *testing.T, f func(info introTestInfo)) {
}

var (
callQid uint32
vineID uint32
callQid uint32
vineID uint32
promiseExportID uint32
)
{
// Read the call; should start off with a promise, record the ID:
Expand All @@ -222,7 +225,7 @@ func introTest(t *testing.T, f func(info introTestInfo)) {
require.Equal(t, 1, len(call.Params.CapTable))
desc := call.Params.CapTable[0]
require.Equal(t, rpccp.CapDescriptor_Which_senderPromise, desc.Which)
promiseExportID := desc.SenderPromise
promiseExportID = desc.SenderPromise

// Read the resolve for that promise, which should point to a third party cap:
rmsg, release, err = recvMessage(ctx, rTrans)
Expand All @@ -245,6 +248,7 @@ func introTest(t *testing.T, f func(info introTestInfo)) {
Dq: dq,
ProvideQID: provideQid,
CallQID: callQid,
PromiseID: promiseExportID,
VineID: vineID,
EmptyExportID: emptyExportID,
EmptyFut: emptyFut,
Expand Down Expand Up @@ -399,6 +403,45 @@ func TestVineDropCancelsHandoff(t *testing.T) {
})
}

// Checks that a third party disembargo is propogated correctly.
func TestDisembargoThirdPartyCap(t *testing.T) {
introTest(t, func(info introTestInfo) {
ctx := context.Background()
rTrans := info.Recipient.Trans
pTrans := info.Provider.Trans

require.NoError(t, sendMessage(ctx, rTrans, &rpcMessage{
Which: rpccp.Message_Which_disembargo,
Disembargo: &rpcDisembargo{
Target: rpcMessageTarget{
Which: rpccp.MessageTarget_Which_importedCap,
ImportedCap: info.PromiseID,
},
Context: rpcDisembargoContext{
Which: rpccp.Disembargo_context_Which_accept,
},
},
}))

rmsg, release, err := recvMessage(ctx, pTrans)
require.NoError(t, err)
info.Dq.Defer(release)

require.Equal(t, rpccp.Message_Which_disembargo, rmsg.Which)
require.Equal(t, info.ProvideQID, rmsg.Disembargo.Target.Which)
require.Equal(t, info.ProvideQID, rmsg.Disembargo.Target.PromisedAnswer.QuestionID)
require.Equal(t, 0, len(rmsg.Disembargo.Target.PromisedAnswer.Transform))

require.Equal(t,
rpcDisembargoContext{
Which: rpccp.Disembargo_context_Which_provide,
Provide: info.ProvideQID,
},
rmsg.Disembargo.Context,
)
})
}

// Helper that receives and replies to a bootstrap message on trans, returning a SenderHosted
// capability with the given export ID.
func doBootstrap(t *testing.T, bootstrapExportID uint32, trans rpc.Transport) {
Expand Down
5 changes: 5 additions & 0 deletions rpc/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func (c *lockedConn) send3PHPromise(
// Return an error to indicate we didn't send the resolve:
return errReceiverLostInterest
}
// We have to set this before sending the provide, so we're ready
// for a disembargo. It's okay to wait up until now though, since
// the receiver shouldn't send one until it sees the resolution:
c.lk.exports[promiseID].provide = maybe.New(provideQ)

resolve, err := m.NewResolve()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ func (c *Conn) handleDisembargo(ctx context.Context, in transport.IncomingMessag
return err
}
return withLockedConn1(q.c, func(c *lockedConn) error {
if !q.flags.Contains(provideDisembargoSent) {
if q.flags.Contains(provideDisembargoSent) {
return errors.New("disembargo already sent to export #" + str.Utod(id))
}
q.flags |= provideDisembargoSent
Expand Down

0 comments on commit 24b569a

Please sign in to comment.