mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 01:25:38 -05:00
Merge from vscode 52dcb723a39ae75bee1bd56b3312d7fcdc87aeed (#6719)
This commit is contained in:
@@ -62,9 +62,9 @@ export class TestDiskFileSystemProvider extends DiskFileSystemProvider {
|
||||
|
||||
totalBytesRead: number = 0;
|
||||
|
||||
private invalidStatSize: boolean;
|
||||
private invalidStatSize: boolean = false;
|
||||
|
||||
private _testCapabilities: FileSystemProviderCapabilities;
|
||||
private _testCapabilities!: FileSystemProviderCapabilities;
|
||||
get capabilities(): FileSystemProviderCapabilities {
|
||||
if (!this._testCapabilities) {
|
||||
this._testCapabilities =
|
||||
@@ -115,7 +115,7 @@ export class TestDiskFileSystemProvider extends DiskFileSystemProvider {
|
||||
}
|
||||
}
|
||||
|
||||
suite('Disk File Service', () => {
|
||||
suite('Disk File Service', function () {
|
||||
|
||||
const parentDir = getRandomTestPath(tmpdir(), 'vsctests', 'diskfileservice');
|
||||
const testSchema = 'test';
|
||||
@@ -127,6 +127,12 @@ suite('Disk File Service', () => {
|
||||
|
||||
const disposables = new DisposableStore();
|
||||
|
||||
// Given issues such as https://github.com/microsoft/vscode/issues/78602
|
||||
// we see random test failures when accessing the native file system. To
|
||||
// diagnose further, we retry node.js file access tests up to 3 times to
|
||||
// rule out any random disk issue.
|
||||
this.retries(3);
|
||||
|
||||
setup(async () => {
|
||||
const logService = new NullLogService();
|
||||
|
||||
@@ -613,7 +619,7 @@ suite('Disk File Service', () => {
|
||||
await testMoveFolderAcrossProviders();
|
||||
});
|
||||
|
||||
test('move - directory - across providers (unbuffered => buffered)', async () => {
|
||||
test('move - directory - across providers (unbuffered => buffered)', async function () {
|
||||
setCapabilities(fileProvider, FileSystemProviderCapabilities.FileReadWrite);
|
||||
setCapabilities(testProvider, FileSystemProviderCapabilities.FileOpenReadWriteClose);
|
||||
|
||||
@@ -1915,4 +1921,94 @@ suite('Disk File Service', () => {
|
||||
function hasChange(changes: IFileChange[], type: FileChangeType, resource: URI): boolean {
|
||||
return changes.some(change => change.type === type && isEqual(change.resource, resource));
|
||||
}
|
||||
});
|
||||
|
||||
test('read - mixed positions', async () => {
|
||||
const resource = URI.file(join(testDir, 'lorem.txt'));
|
||||
|
||||
// read multiple times from position 0
|
||||
let buffer = VSBuffer.alloc(1024);
|
||||
let fd = await fileProvider.open(resource, { create: false });
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await fileProvider.read(fd, 0, buffer.buffer, 0, 26);
|
||||
assert.equal(buffer.slice(0, 26).toString(), 'Lorem ipsum dolor sit amet');
|
||||
}
|
||||
await fileProvider.close(fd);
|
||||
|
||||
// read multiple times at various locations
|
||||
buffer = VSBuffer.alloc(1024);
|
||||
fd = await fileProvider.open(resource, { create: false });
|
||||
|
||||
let posInFile = 0;
|
||||
|
||||
await fileProvider.read(fd, posInFile, buffer.buffer, 0, 26);
|
||||
assert.equal(buffer.slice(0, 26).toString(), 'Lorem ipsum dolor sit amet');
|
||||
posInFile += 26;
|
||||
|
||||
await fileProvider.read(fd, posInFile, buffer.buffer, 0, 1);
|
||||
assert.equal(buffer.slice(0, 1).toString(), ',');
|
||||
posInFile += 1;
|
||||
|
||||
await fileProvider.read(fd, posInFile, buffer.buffer, 0, 12);
|
||||
assert.equal(buffer.slice(0, 12).toString(), ' consectetur');
|
||||
posInFile += 12;
|
||||
|
||||
await fileProvider.read(fd, 98 /* no longer in sequence of posInFile */, buffer.buffer, 0, 9);
|
||||
assert.equal(buffer.slice(0, 9).toString(), 'fermentum');
|
||||
|
||||
await fileProvider.read(fd, 27, buffer.buffer, 0, 12);
|
||||
assert.equal(buffer.slice(0, 12).toString(), ' consectetur');
|
||||
|
||||
await fileProvider.read(fd, 26, buffer.buffer, 0, 1);
|
||||
assert.equal(buffer.slice(0, 1).toString(), ',');
|
||||
|
||||
await fileProvider.read(fd, 0, buffer.buffer, 0, 26);
|
||||
assert.equal(buffer.slice(0, 26).toString(), 'Lorem ipsum dolor sit amet');
|
||||
|
||||
await fileProvider.read(fd, posInFile /* back in sequence */, buffer.buffer, 0, 11);
|
||||
assert.equal(buffer.slice(0, 11).toString(), ' adipiscing');
|
||||
|
||||
await fileProvider.close(fd);
|
||||
});
|
||||
|
||||
test('write - mixed positions', async () => {
|
||||
const resource = URI.file(join(testDir, 'lorem.txt'));
|
||||
|
||||
const buffer = VSBuffer.alloc(1024);
|
||||
const fdWrite = await fileProvider.open(resource, { create: true });
|
||||
const fdRead = await fileProvider.open(resource, { create: false });
|
||||
|
||||
let posInFileWrite = 0;
|
||||
let posInFileRead = 0;
|
||||
|
||||
const initialContents = VSBuffer.fromString('Lorem ipsum dolor sit amet');
|
||||
await fileProvider.write(fdWrite, posInFileWrite, initialContents.buffer, 0, initialContents.byteLength);
|
||||
posInFileWrite += initialContents.byteLength;
|
||||
|
||||
await fileProvider.read(fdRead, posInFileRead, buffer.buffer, 0, 26);
|
||||
assert.equal(buffer.slice(0, 26).toString(), 'Lorem ipsum dolor sit amet');
|
||||
posInFileRead += 26;
|
||||
|
||||
const contents = VSBuffer.fromString('Hello World');
|
||||
|
||||
await fileProvider.write(fdWrite, posInFileWrite, contents.buffer, 0, contents.byteLength);
|
||||
posInFileWrite += contents.byteLength;
|
||||
|
||||
await fileProvider.read(fdRead, posInFileRead, buffer.buffer, 0, contents.byteLength);
|
||||
assert.equal(buffer.slice(0, contents.byteLength).toString(), 'Hello World');
|
||||
posInFileRead += contents.byteLength;
|
||||
|
||||
await fileProvider.write(fdWrite, 6, contents.buffer, 0, contents.byteLength);
|
||||
|
||||
await fileProvider.read(fdRead, 0, buffer.buffer, 0, 11);
|
||||
assert.equal(buffer.slice(0, 11).toString(), 'Lorem Hello');
|
||||
|
||||
await fileProvider.write(fdWrite, posInFileWrite, contents.buffer, 0, contents.byteLength);
|
||||
posInFileWrite += contents.byteLength;
|
||||
|
||||
await fileProvider.read(fdRead, posInFileWrite - contents.byteLength, buffer.buffer, 0, contents.byteLength);
|
||||
assert.equal(buffer.slice(0, contents.byteLength).toString(), 'Hello World');
|
||||
|
||||
await fileProvider.close(fdWrite);
|
||||
await fileProvider.close(fdRead);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user