Skip to content

Commit

Permalink
Enable strictNullCheck in end-to-end-tests (#3935)
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisman authored Oct 14, 2020
1 parent 99b2c9a commit bd511e1
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 14 deletions.
23 changes: 23 additions & 0 deletions lerna-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/test/end-to-end-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"old-container-loader": "npm:@fluidframework/container-loader@^0.26.0",
"old-container-runtime": "npm:@fluidframework/container-runtime@^0.26.0",
"old-counter": "npm:@fluidframework/counter@^0.26.0",
"old-datastore-definitions": "npm:@fluidframework/datastore-definitions@^0.26.0",
"old-driver-definitions": "npm:@fluidframework/driver-definitions@^0.26.0",
"old-ink": "npm:@fluidframework/ink@^0.26.0",
"old-local-driver": "npm:@fluidframework/local-driver@^0.26.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ describe(`r11s End-To-End tests`, () => {
const tenantSecret = process.env.fluid__webpack__tenantSecret;
const fluidHost = process.env.fluid__webpack__fluidHost;

assert(bearerSecret, "Missing bearer secret");
assert(tenantId, "Missing tenantId");
assert(tenantSecret, "Missing tenant secret");
assert(fluidHost, "Missing Fluid host");

return new InsecureUrlResolver(
fluidHost,
fluidHost.replace("www", "alfred"),
Expand Down Expand Up @@ -114,6 +119,7 @@ describe(`r11s End-To-End tests`, () => {

// Now attach the container and get the sub component.
await container.attach(request);
assert(container.resolvedUrl, "attached container should have resolved URL");

// Now load the container from another loader.
const urlResolver2 = getResolver();
Expand Down
3 changes: 1 addition & 2 deletions packages/test/end-to-end-tests/src/test/compatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface ICompatTestOptions {

// convert a channel factory registry for TestFluidDataStoreFactory to one with old channel factories
function convertRegistry(registry: ChannelFactoryRegistry = []): old.ChannelFactoryRegistry {
const oldRegistry = [];
const oldRegistry: [string | undefined, old.IChannelFactory][] = [];
for (const [key, factory] of registry) {
switch (factory.type) {
case SharedMap.getFactory().type:
Expand Down Expand Up @@ -90,7 +90,6 @@ function convertRegistry(registry: ChannelFactoryRegistry = []): old.ChannelFact
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return oldRegistry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function generate(

await opProcessingController.pauseProcessing();

const addP = [];
const addP: Promise<void>[] = [];
for (const item of input) {
addP.push(collection1.add(item));
}
Expand Down Expand Up @@ -301,7 +301,7 @@ function generate(
removeCount3 += 1;
});

const p = [];
const p: Promise<void>[] = [];
p.push(collection1.add(input[0]));
// drain the outgoing so that the next set will come after
await opProcessingController.processOutgoing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function generate(name: string, ctor: ISharedObjectConstructor<IConsensusRegiste
const write3P = collection3.write("key1", "value3");
await Promise.all([write1P, write2P, write3P]);
const versions = collection1.readVersions("key1");
assert(versions);
assert.strictEqual(versions.length, 3, "Concurrent updates were not preserved");
assert.strictEqual(versions[0], "value1", "Incorrect update sequence");
assert.strictEqual(versions[1], "value2", "Incorrect update sequence");
Expand All @@ -119,20 +120,24 @@ function generate(name: string, ctor: ISharedObjectConstructor<IConsensusRegiste
const write3P = collection3.write("key1", "value3");
await Promise.all([write1P, write2P, write3P]);
const versions = collection1.readVersions("key1");
assert(versions);
assert.strictEqual(versions.length, 3, "Concurrent updates were not preserved");

await collection3.write("key1", "value4");
const versions2 = collection1.readVersions("key1");
assert(versions2);
assert.strictEqual(versions2.length, 1, "Happened after value did not overwrite");
assert.strictEqual(versions2[0], "value4", "Happened after value did not overwrite");

await collection2.write("key1", "value5");
const versions3 = collection1.readVersions("key1");
assert(versions3);
assert.strictEqual(versions3.length, 1, "Happened after value did not overwrite");
assert.strictEqual(versions3[0], "value5", "Happened after value did not overwrite");

await collection1.write("key1", "value6");
const versions4 = collection1.readVersions("key1");
assert(versions4);
assert.strictEqual(versions4.length, 1, "Happened after value did not overwrite");
assert.strictEqual(versions4[0], "value6", "Happened after value did not overwrite");

Expand All @@ -141,13 +146,15 @@ function generate(name: string, ctor: ISharedObjectConstructor<IConsensusRegiste
const write9P = collection3.write("key1", "value9");
await Promise.all([write7P, write8P, write9P]);
const versions5 = collection3.readVersions("key1");
assert(versions5);
assert.strictEqual(versions5.length, 3, "Concurrent happened after updates should overwrite and preserve");
assert.strictEqual(versions5[0], "value7", "Incorrect update sequence");
assert.strictEqual(versions5[1], "value8", "Incorrect update sequence");
assert.strictEqual(versions5[2], "value9", "Incorrect update sequence");

await collection2.write("key1", "value10");
const versions6 = collection2.readVersions("key1");
assert(versions6);
assert.strictEqual(versions6.length, 1, "Happened after value did not overwrite");
assert.strictEqual(versions6[0], "value10", "Happened after value did not overwrite");
});
Expand Down
4 changes: 2 additions & 2 deletions packages/test/end-to-end-tests/src/test/contextReload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const V2 = "0.2.0";
// different versions (defined below) are used to test context reload.
abstract class TestDataStore extends DataObject {
public static readonly type = "@fluid-example/test-dataStore";
public readonly version: string;
public abstract readonly version: string;
public get _runtime() { return this.runtime; }
public get _root() { return this.root; }
}
Expand All @@ -56,7 +56,7 @@ class TestDataStoreV2 extends TestDataStore {
// different runtime versions.
abstract class OldTestDataStore extends old.DataObject {
public static readonly type = "@fluid-example/test-dataStore";
public readonly version: string;
public abstract readonly version: string;
public get _runtime() { return this.runtime; }
public get _root() { return this.root; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ describe(`Dehydrate Rehydrate Container Test`, () => {
// Now load the container from another loader.
const urlResolver2 = new LocalResolver();
const loader2 = createTestLoader(urlResolver2);
assert(rehydratedContainer.resolvedUrl);
const requestUrl2 = await urlResolver2.getAbsoluteUrl(rehydratedContainer.resolvedUrl, "");
const container2 = await loader2.resolve({ url: requestUrl2 });

Expand Down Expand Up @@ -382,6 +383,7 @@ describe(`Dehydrate Rehydrate Container Test`, () => {
// Now load the container from another loader.
const urlResolver2 = new LocalResolver();
const loader2 = createTestLoader(urlResolver2);
assert(rehydratedContainer.resolvedUrl);
const requestUrl2 = await urlResolver2.getAbsoluteUrl(rehydratedContainer.resolvedUrl, "");
const container2 = await loader2.resolve({ url: requestUrl2 });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const tests = (args: ICompatLocalTestObjectProvider) => {
assert.strictEqual(container.getQuorum().getMembers().size, 0, "Quorum should not contain any members");
assert.strictEqual(container.connectionState, ConnectionState.Disconnected,
"Container should be in disconnected state!!");
assert.strictEqual(container.chaincodePackage.package, pkg.package,
assert.strictEqual(container.chaincodePackage?.package, pkg.package,
"Package should be same as provided");
assert.strictEqual(container.id, "", "Detached container's id should be empty string");
assert.strictEqual(container.clientDetails.capabilities.interactive, true,
Expand Down Expand Up @@ -155,6 +155,7 @@ const tests = (args: ICompatLocalTestObjectProvider) => {
// Now load the container from another loader.
const loader2 = args.makeTestLoader(registry);
// Create a new request url from the resolvedUrl of the first container.
assert(container.resolvedUrl);
const requestUrl2 = await args.urlResolver.getAbsoluteUrl(container.resolvedUrl, "");
const container2 = await loader2.resolve({ url: requestUrl2 });

Expand Down Expand Up @@ -209,6 +210,7 @@ const tests = (args: ICompatLocalTestObjectProvider) => {
// Now load the container from another loader.
const loader2 = args.makeTestLoader(registry);
// Create a new request url from the resolvedUrl of the first container.
assert(container.resolvedUrl);
const requestUrl2 = await args.urlResolver.getAbsoluteUrl(container.resolvedUrl, "");
const container2 = await loader2.resolve({ url: requestUrl2 });

Expand Down Expand Up @@ -585,6 +587,7 @@ describe("Detached Container", () => {
await container.attach(request);

// Create a new request url from the resolvedUrl of the first container.
assert(container.resolvedUrl);
const requestUrl2 = await args.urlResolver.getAbsoluteUrl(container.resolvedUrl, "");
const container2 = await loader.resolve({ url: requestUrl2 });
assert.strictEqual(container, container2, "Both containers should be same");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import * as assert from "assert";
import { strict as assert } from "assert";
import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqueduct";
import { IContainer, IFluidCodeDetails, IProxyLoaderFactory } from "@fluidframework/container-definitions";
import { Container, Loader } from "@fluidframework/container-loader";
Expand Down Expand Up @@ -162,6 +162,7 @@ describe("Document Dirty", () => {

it(`doesn't affect document state while reconnecting`, async () => {
// Disconnect the client.
assert(container.clientId);
documentServiceFactory.disconnectClient(container.clientId, "Disconnected for testing");

// Wait for the Container to get reconnected.
Expand All @@ -176,6 +177,7 @@ describe("Document Dirty", () => {
describe("Disconnected state", () => {
it(`sets operations when disconnected and then reconnects to process them`, async () => {
// Disconnect the client.
assert(container.clientId);
documentServiceFactory.disconnectClient(container.clientId, "Disconnected for testing");

// Set values in DDSes in disconnected state.
Expand Down Expand Up @@ -233,6 +235,7 @@ describe("Document Dirty", () => {
"Document is marked dirty on edit");

// Disconnect the client.
assert(container.clientId);
documentServiceFactory.disconnectClient(container.clientId, "Disconnected for testing");

assert.equal(wasMarkedDirtyCount, 1,
Expand Down Expand Up @@ -273,6 +276,7 @@ describe("Document Dirty", () => {
describe("Disconnected state with batch operations", () => {
it(`sets operations when disconnected and then reconnects to process them`, async () => {
// Disconnect the client.
assert(container.clientId);
documentServiceFactory.disconnectClient(container.clientId, "Disconnected for testing");

// Set batch values in DDSes in disconnected state.
Expand Down Expand Up @@ -335,6 +339,8 @@ describe("Document Dirty", () => {
assert.equal(containerRuntime.isDocumentDirty(), true,
"Document is marked dirty on edit");

assert(container.clientId);

// Disconnect the client.
documentServiceFactory.disconnectClient(container.clientId, "Disconnected for testing");

Expand Down
1 change: 1 addition & 0 deletions packages/test/end-to-end-tests/src/test/oldVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { Container, Loader } from "old-container-loader";
export { ContainerRuntime, IContainerRuntimeOptions } from "old-container-runtime";
export { IDocumentServiceFactory } from "old-driver-definitions";
export { IFluidDataStoreFactory } from "old-runtime-definitions";
export { IChannelFactory } from "old-datastore-definitions";
export {
createLocalLoader,
createAndAttachContainer,
Expand Down
11 changes: 10 additions & 1 deletion packages/test/end-to-end-tests/src/test/opsOnReconnect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import * as assert from "assert";
import { strict as assert } from "assert";
import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqueduct";
import { IContainer, IFluidCodeDetails, ILoader, IProxyLoaderFactory } from "@fluidframework/container-definitions";
import { ConnectionState, Container, Loader } from "@fluidframework/container-loader";
Expand Down Expand Up @@ -163,6 +163,7 @@ describe("Ops on Reconnect", () => {
await setupSecondContainersDataObject();

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -197,6 +198,7 @@ describe("Ops on Reconnect", () => {
await setupSecondContainersDataObject();

// Nack the client.
assert(container1.clientId);
documentServiceFactory.nackClient(container1.clientId);

// The Container should be in disconnected state because DeltaManager disconnects on getting Nack'd.
Expand Down Expand Up @@ -231,6 +233,7 @@ describe("Ops on Reconnect", () => {
await setupSecondContainersDataObject();

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -289,6 +292,7 @@ describe("Ops on Reconnect", () => {
assert.ok(container2Object2, "Could not get dataStore2 in the second container");

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -339,6 +343,7 @@ describe("Ops on Reconnect", () => {
container1Object1Directory.set("key6", "value6");

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -399,6 +404,7 @@ describe("Ops on Reconnect", () => {
container1Object2Map2.set("key8", "value8");

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -431,6 +437,7 @@ describe("Ops on Reconnect", () => {
await setupSecondContainersDataObject();

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -472,6 +479,7 @@ describe("Ops on Reconnect", () => {
await setupSecondContainersDataObject();

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down Expand Up @@ -519,6 +527,7 @@ describe("Ops on Reconnect", () => {
await setupSecondContainersDataObject();

// Disconnect the client.
assert(container1.clientId);
documentServiceFactory.disconnectClient(container1.clientId, "Disconnected for testing");

// The Container should be in disconnected state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,12 @@ describe("SharedInterval", () => {
assert.equal(serialized3.length, 3, "Incorrect interval collection size in container 3");

const interval1From3 = serialized3[0] as ISerializedInterval;
assert(interval1From3.properties);
const comment1From3 = await (interval1From3.properties.story as IFluidHandle<SharedString>).get();
assert.equal(
comment1From3.getText(0, 12), "a comment...", "Incorrect text in interval collection's shared string");
const interval3From3 = serialized3[2] as ISerializedInterval;
assert(interval3From3.properties);
const mapFrom3 = await (interval3From3.properties.story as IFluidHandle<SharedMap>).get();
assert.equal(
mapFrom3.get("nestedKey"), "nestedValue", "Incorrect value in interval collection's shared map");
Expand All @@ -352,6 +354,7 @@ describe("SharedInterval", () => {
const serializedInterval1FromSnapshot =
(parsedSnapshot["intervalCollections/comments"].value as ISerializedInterval[])[0];
// The "story" is the ILocalValue of the handle pointing to the SharedString
assert(serializedInterval1FromSnapshot.properties);
const handleLocalValueFromSnapshot = serializedInterval1FromSnapshot.properties.story as { type: string };
assert.equal(
handleLocalValueFromSnapshot.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import * as assert from "assert";
import { strict as assert } from "assert";
import { DataObject, DataObjectFactory } from "@fluidframework/aqueduct";
import { UpgradeManager } from "@fluidframework/base-host";
import {
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("UpgradeManager", () => {
const container1 = await createContainer(TestDataObject.getFactory());

// Load the second Container.
const container2 = await loadContainer(TestDataObject.getFactory());
const container2 = await loadContainer(TestDataObject.getFactory()) as Container;

const upgradeManager = new UpgradeManager((container1 as any).context.runtime);

Expand All @@ -198,7 +198,8 @@ describe("UpgradeManager", () => {
upgradeManager.upgrade(codeDetails);

// disconnect one client, which should initiate upgrade
documentServiceFactory.disconnectClient((container2 as Container).clientId, "test");
assert(container2.clientId);
documentServiceFactory.disconnectClient(container2.clientId, "test");

await upgradeP;
});
Expand Down
Loading

0 comments on commit bd511e1

Please sign in to comment.