Skip to content

Commit d48747d

Browse files
committed
itest: add main universe server as federation member
By default we want all new tapd instances to be synced with the main universe server, so we add it as a federation member unless specifically disabled.
1 parent 40cec8c commit d48747d

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

itest/addrs_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ func testMultiAddress(t *harnessTest) {
189189
func testAddressAssetSyncer(t *harnessTest) {
190190
// We'll kick off the test by making a new node, without hooking it up
191191
// to any existing Universe server.
192-
bob := setupTapdHarness(t.t, t, t.lndHarness.Bob, nil)
192+
bob := setupTapdHarness(
193+
t.t, t, t.lndHarness.Bob, t.universeServer,
194+
func(params *tapdHarnessParams) {
195+
params.noDefaultUniverseSync = true
196+
},
197+
)
193198
defer func() {
194199
require.NoError(t.t, bob.stop(!*noDelete))
195200
}()
@@ -315,8 +320,9 @@ func testAddressAssetSyncer(t *harnessTest) {
315320
restartBobNoUniSync := func(disableSyncer bool) {
316321
require.NoError(t.t, bob.stop(!*noDelete))
317322
bob = setupTapdHarness(
318-
t.t, t, t.lndHarness.Bob, nil,
323+
t.t, t, t.lndHarness.Bob, t.universeServer,
319324
func(params *tapdHarnessParams) {
325+
params.noDefaultUniverseSync = true
320326
params.addrAssetSyncerDisable = disableSyncer
321327
},
322328
)

itest/mint_batch_stress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func testMintBatchNStressTest(t *harnessTest, batchSize int,
5757
// If we create a second tapd instance and sync the universe state,
5858
// the synced tree should match the source tree.
5959
bob := setupTapdHarness(
60-
t.t, t, t.lndHarness.Bob, nil,
60+
t.t, t, t.lndHarness.Bob, t.universeServer,
6161
)
6262
defer func() {
6363
require.NoError(t.t, bob.stop(!*noDelete))

itest/test_harness.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,25 @@ func (h *harnessTest) syncUniverseState(target, syncer *tapdHarness,
240240
require.Equal(h.t, numExpectedAssets, numAssets)
241241
}
242242

243+
// addFederationServer adds a new federation server to the given tapd harness.
244+
func (h *harnessTest) addFederationServer(host string, target *tapdHarness) {
245+
ctxt, cancel := context.WithTimeout(
246+
context.Background(), defaultWaitTimeout,
247+
)
248+
defer cancel()
249+
250+
_, err := target.AddFederationServer(
251+
ctxt, &unirpc.AddFederationServerRequest{
252+
Servers: []*unirpc.UniverseFederationServer{
253+
{
254+
Host: host,
255+
},
256+
},
257+
},
258+
)
259+
require.NoError(h.t, err)
260+
}
261+
243262
// nextAvailablePort returns the first port that is available for listening by
244263
// a new node. It panics if no port is found and the maximum available TCP port
245264
// is reached.
@@ -346,6 +365,10 @@ type tapdHarnessParams struct {
346365
// startupSyncNumAssets is the number of assets that are expected to be
347366
// synced from the above node.
348367
startupSyncNumAssets int
368+
369+
// noDefaultUniverseSync indicates whether the default universe server
370+
// should be added as a federation server or not.
371+
noDefaultUniverseSync bool
349372
}
350373

351374
type Option func(*tapdHarnessParams)
@@ -391,6 +414,12 @@ func setupTapdHarness(t *testing.T, ht *harnessTest,
391414
err = tapdHarness.start(params.expectErrExit)
392415
require.NoError(t, err)
393416

417+
// Add the default universe server as a federation server, unless
418+
// specifically indicated by the caller.
419+
if !params.noDefaultUniverseSync {
420+
ht.addFederationServer(universe.service.rpcHost(), tapdHarness)
421+
}
422+
394423
// Before we exit, we'll check to see if we need to sync the universe
395424
// state.
396425
if params.startupSyncNode != nil {

itest/universe_pagination_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func testUniversePaginationSimple(t *harnessTest) {
3636
// If we create a second tapd instance and sync the universe state,
3737
// the synced tree should match the source tree.
3838
bob := setupTapdHarness(
39-
t.t, t, t.lndHarness.Bob, nil,
39+
t.t, t, t.lndHarness.Bob, t.universeServer,
4040
)
4141
defer func() {
4242
require.NoError(t.t, bob.stop(!*noDelete))

itest/universe_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func testUniverseSync(t *harnessTest) {
4242
// With those assets created, we'll now create a new node that we'll
4343
// use to exercise the Universe sync.
4444
bob := setupTapdHarness(
45-
t.t, t, t.lndHarness.Bob, nil,
45+
t.t, t, t.lndHarness.Bob, t.universeServer,
46+
func(params *tapdHarnessParams) {
47+
params.noDefaultUniverseSync = true
48+
},
4649
)
4750
defer func() {
4851
require.NoError(t.t, bob.stop(!*noDelete))
@@ -385,7 +388,10 @@ func testUniverseFederation(t *harnessTest) {
385388
// We'll kick off the test by making a new node, without hooking it up to
386389
// any existing Universe server.
387390
bob := setupTapdHarness(
388-
t.t, t, t.lndHarness.Bob, nil,
391+
t.t, t, t.lndHarness.Bob, t.universeServer,
392+
func(params *tapdHarnessParams) {
393+
params.noDefaultUniverseSync = true
394+
},
389395
)
390396
defer func() {
391397
require.NoError(t.t, bob.stop(!*noDelete))

0 commit comments

Comments
 (0)