Skip to content

Commit

Permalink
Fixes syncer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez committed Jul 30, 2024
1 parent 523e691 commit 7dda79c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/services/registrysyncer/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *LocalRegistry) MarshalJSON() ([]byte, error) {

idsToCapabilities := make(map[string]capabilitiesRegistryCapabilityInfo)
for k, v := range t.IDsToCapabilities {
idsToCapabilities[fmt.Sprintf("%x", k[:])] = capabilitiesRegistryCapabilityInfo{
idsToCapabilities[k] = capabilitiesRegistryCapabilityInfo{
ID: v.ID,
CapabilityType: int(v.CapabilityType),
}
Expand Down
2 changes: 2 additions & 0 deletions core/services/registrysyncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ func (s *registrySyncer) sync(ctx context.Context, isInitialSync bool) error {
if isInitialSync {
s.lggr.Debug("syncing with local registry")
lr, err = s.orm.latestState(ctx)
lr.lggr = s.lggr
lr.peerWrapper = s.peerWrapper
if err != nil {
s.lggr.Errorw("failed to sync with local registry, using remote registry instead", "error", err)
}
Expand Down
22 changes: 20 additions & 2 deletions core/services/registrysyncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,26 @@ func TestSyncer_DBIntegration(t *testing.T) {
_, err = reg.AddNodes(owner, nodes)
require.NoError(t, err)

config := &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTriggerConfig{
RemoteTriggerConfig: &capabilitiespb.RemoteTriggerConfig{
RegistrationRefresh: durationpb.New(20 * time.Second),
RegistrationExpiry: durationpb.New(60 * time.Second),
// F + 1
MinResponsesToAggregate: uint32(1) + 1,
},
},
}
configb, err := proto.Marshal(config)
if err != nil {
require.NoError(t, err)
}

cfgs := []kcr.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: cid,
Config: []byte(`{"hello": "world"}`),
Config: configb,
},
}
_, err = reg.AddDON(
Expand Down Expand Up @@ -421,8 +437,10 @@ func TestSyncer_DBIntegration(t *testing.T) {
time.Sleep(1 * time.Second) // TODO: figure out another alternative to wait for the state to be stored in the DB
st, err := syncer.orm.latestState(ctx)
require.NoError(t, err)
st.peerWrapper = syncer.peerWrapper
st.lggr = syncer.lggr

assert.Equal(t, s, *st, "expected the state to be the same as the one stored in the DB")
assert.Equal(t, s, st, "expected the state to be the same as the one stored in the DB")

err = syncer.sync(ctx, true) // should load the data from the DB
require.NoError(t, err)
Expand Down

0 comments on commit 7dda79c

Please sign in to comment.