Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Add check for missing shard #689

Merged
merged 1 commit into from
Apr 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/bridge-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ BridgeClient.prototype.createFileStream = function(bucket, file, opt, cb) {
return done(err);
}

// When erasure encoding is implemented, this can just
// become a missing shard that is recovered.
for (var i = 0; i < pointers.length; i++) {
if (!pointers[i].farmer) {
return done(new Error('Missing shard'));
}
}

skip += limit;
done(null, pointers);
});
Expand Down
45 changes: 45 additions & 0 deletions test/bridge-client/index.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,51 @@ describe('BridgeClient', function() {
});
});

it('should error if farmer is missing to download', function(done) {
var client = new BridgeClient();
var _getFilePointers = sinon.stub(
client,
'getFilePointers'
);
_getFilePointers.onFirstCall().callsArgWith(1, null, [
{
size: 512,
farmer: {
address: '127.0.0.1',
port: 8080,
nodeID: utils.rmd160('nodeid')
}
},
{
size: 512,
}
]);
_getFilePointers.onSecondCall().callsArgWith(1, null, [
{
size: 512,
farmer: {
address: '127.0.0.1',
port: 8080,
nodeID: utils.rmd160('nodeid')
}
}
]);
sinon.stub(client, 'getFileInfo').callsArgWith(2, null, {
size: 512 * 3
});
_getFilePointers.onThirdCall().callsArgWith(1, null, []);
var _createToken = sinon.stub(
client,
'createToken'
).callsArgWith(2, null, 'token');
client.createFileStream('bucket', 'file', {}, function(err) {
_createToken.restore();
_getFilePointers.restore();
expect(err.message).to.equal('Missing shard');
done();
});
});

it('should emit stream error if slice cannot get token', function(done) {
var client = new BridgeClient();
var _getFilePointers = sinon.stub(
Expand Down