Skip to content

Commit e643548

Browse files
prog
1 parent 416d090 commit e643548

File tree

1 file changed

+48
-21
lines changed

1 file changed

+48
-21
lines changed

share/availability/full/reconstruction_test.go

+48-21
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,39 @@ func TestShareAvailable_OneFullNode(t *testing.T) {
3737
{
3838
name: "fully recoverable",
3939
origSquareSize: 16,
40-
lightNodes: 24,
40+
lightNodes: 24, // ~99% chance of recoverability
4141
sampleAmount: 20,
4242
recoverability: FullyRecoverable,
4343
expectedFailure: false,
4444
},
45+
{
46+
name: "fully recoverable, not enough LNs",
47+
origSquareSize: 16,
48+
lightNodes: 19, // ~0.7% chance of recoverability
49+
sampleAmount: 20,
50+
recoverability: FullyRecoverable,
51+
expectedFailure: true,
52+
},
4553
{
4654
name: "barely recoverable",
4755
origSquareSize: 16,
48-
lightNodes: 69,
56+
lightNodes: 230, // 99% chance of recoverability
4957
sampleAmount: 20,
5058
recoverability: BarelyRecoverable,
5159
expectedFailure: false,
5260
},
61+
{
62+
name: "barely recoverable, not enough LNs",
63+
origSquareSize: 16,
64+
lightNodes: 22, // ~0.3% chance of recoverability
65+
sampleAmount: 20,
66+
recoverability: BarelyRecoverable,
67+
expectedFailure: true,
68+
},
5369
{
5470
name: "unrecoverable",
5571
origSquareSize: 16,
56-
lightNodes: 69,
72+
lightNodes: 230,
5773
sampleAmount: 20,
5874
recoverability: Unrecoverable,
5975
expectedFailure: true,
@@ -95,12 +111,7 @@ func TestShareAvailable_OneFullNode(t *testing.T) {
95111
}(i)
96112
}
97113

98-
errg, errCtx := errgroup.WithContext(ctx)
99-
errg.Go(func() error {
100-
return full.SharesAvailable(errCtx, root)
101-
})
102-
103-
err := errg.Wait()
114+
err := full.SharesAvailable(ctx, root)
104115
if tt.expectedFailure {
105116
require.Error(t, err)
106117
} else {
@@ -134,20 +145,34 @@ func TestShareAvailable_ConnectedFullNodes(t *testing.T) {
134145
recoverability: FullyRecoverable,
135146
expectedFailure: false,
136147
},
148+
{
149+
name: "fully recoverable, not enough LNs",
150+
origSquareSize: 16,
151+
lightNodes: 19, // ~0.7% chance of recoverability
152+
sampleAmount: 20,
153+
recoverability: FullyRecoverable,
154+
expectedFailure: true,
155+
},
156+
// NOTE: This test contains cases for barely recoverable but
157+
// DisconnectedFullNodes does not. The reasoning for this is that
158+
// DisconnectedFullNodes has the additional contstraint that the data
159+
// should not be reconstructable from a single subnetwork, while this
160+
// test only tests that the data is reconstructable once the subnetworks
161+
// are connected.
137162
{
138163
name: "barely recoverable",
139164
origSquareSize: 16,
140-
lightNodes: 69,
165+
lightNodes: 230, // 99% chance of recoverability
141166
sampleAmount: 20,
142167
recoverability: BarelyRecoverable,
143168
expectedFailure: false,
144169
},
145170
{
146-
name: "unrecoverable",
171+
name: "barely recoverable, not enough LNs",
147172
origSquareSize: 16,
148-
lightNodes: 69,
173+
lightNodes: 22, // ~0.3% chance of recoverability
149174
sampleAmount: 20,
150-
recoverability: Unrecoverable,
175+
recoverability: BarelyRecoverable,
151176
expectedFailure: true,
152177
},
153178
}
@@ -159,7 +184,7 @@ func TestShareAvailable_ConnectedFullNodes(t *testing.T) {
159184
origSquareSize := tt.origSquareSize // k
160185
lightNodes := tt.lightNodes // c
161186

162-
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
187+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
163188
defer cancel()
164189

165190
net := availability_test.NewTestDAGNet(ctx, t)
@@ -266,23 +291,23 @@ func TestShareAvailable_DisconnectedFullNodes(t *testing.T) {
266291
{
267292
name: "fully recoverable",
268293
origSquareSize: 16,
269-
lightNodes: 32,
294+
lightNodes: 24, // ~99% chance of recoverability
270295
sampleAmount: 20,
271296
recoverability: FullyRecoverable,
272297
expectedFailure: false,
273298
},
274299
{
275-
name: "barely recoverable",
300+
name: "fully recoverable, not enough LNs",
276301
origSquareSize: 16,
277-
lightNodes: 70, // actually 69, but needs to be divisible by 2
302+
lightNodes: 19, // ~0.7% chance of recoverability
278303
sampleAmount: 20,
279-
recoverability: BarelyRecoverable,
280-
expectedFailure: false,
304+
recoverability: FullyRecoverable,
305+
expectedFailure: true,
281306
},
282307
{
283308
name: "unrecoverable",
284309
origSquareSize: 16,
285-
lightNodes: 70,
310+
lightNodes: 230,
286311
sampleAmount: 20,
287312
recoverability: Unrecoverable,
288313
expectedFailure: true,
@@ -368,7 +393,9 @@ func TestShareAvailable_DisconnectedFullNodes(t *testing.T) {
368393
// but after they connect
369394
net.Connect(full1.ID(), full2.ID())
370395

371-
// with clean caches from the previous try
396+
// we clear the blockservices not because we need to, but just to
397+
// show its possible to reconstruct without any previously saved
398+
// data from previous attempts.
372399
full1.ClearStorage()
373400
full2.ClearStorage()
374401

0 commit comments

Comments
 (0)