Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Batch] update tests #11836

Merged
merged 4 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions sdk/batch/batch/sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Used in most samples. Retrieve these values from a Batch instance
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
# in the Azure Portal.
AZURE_BATCH_ENDPOINT="<Batch Endpoint>"
AZURE_BATCH_ACCOUNT_NAME="<resource name>"
AZURE_BATCH_ACCOUNT_KEY="<account key>"
# Used to authenticate using Azure AD as a service principal for role-based authentication
# in the tokenAuth sample.
#
# See the documentation for `EnvironmentCredential` at the following link:
# https://docs.microsoft.com/javascript/api/@azure/identity/environmentcredential
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
AZURE_CLIENT_ID="<application id>"
AZURE_CLIENT_SECRET="<application secret>"
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
71 changes: 41 additions & 30 deletions sdk/batch/batch/test/batchClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ describe("Batch Service", () => {
let nonAdminPoolUser: string;
let compute_nodes: string[];

const readStreamToBuffer = function (
const readStreamToBuffer = function(
strm: NodeJS.ReadableStream,
callback: (_a: any, buf: Buffer) => void
) {
const bufs: any[] = [];
strm.on("data", function (d) {
strm.on("data", function(d) {
bufs.push(d);
});
strm.on("end", function () {
strm.on("end", function() {
callback(null, Buffer.concat(bufs));
});
};
Expand All @@ -43,8 +43,8 @@ describe("Batch Service", () => {
batchAccountName = process.env["AZURE_BATCH_ACCOUNT_NAME"]!;
batchAccountKey = process.env["AZURE_BATCH_ACCOUNT_KEY"]!;
batchEndpoint = process.env["AZURE_BATCH_ENDPOINT"]!;
clientId = process.env["CLIENT_ID"]!;
secret = process.env["APPLICATION_SECRET"]!;
clientId = process.env["AZURE_CLIENT_ID"]!;
secret = process.env["AZURE_CLIENT_SECRET"]!;

// dummy thumb
certThumb = "cff2ab63c8c955aaf71989efa641b906558d9fb7";
Expand Down Expand Up @@ -147,8 +147,16 @@ describe("Batch Service", () => {
});

it("should get a pool reference successfully", async () => {
const result = await client.pool.get("nodesdktestpool1");
const metadata = result.metadata![0];
let result, metadata;
while (true) {
result = await client.pool.get("nodesdktestpool1");
metadata = result.metadata![0];
if (result.allocationState === "resizing") {
await wait(10000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not wait. You should probably poll the expected state and then timeout if it doesn't reach it in the specified time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bgklein I missed your comment somehow. @xingwu1 did you consider updating the swagger to provide LROs instead? I think that would make calling the APIs much cleaner.

} else {
break;
}
}

assert.equal(result.id, "nodesdktestpool1");
assert.equal(result.state, "active");
Expand All @@ -167,7 +175,7 @@ describe("Batch Service", () => {
assert.equal(result.userAccounts![0].name, nonAdminPoolUser);
assert.equal(result.userAccounts![0].elevationLevel, "nonadmin");
assert.equal(result._response.status, 200);
});
}).timeout(1000000);

it("should get a pool reference with odata successfully", async () => {
const options: BatchServiceModels.PoolGetOptionalParams = {
Expand All @@ -183,10 +191,10 @@ describe("Batch Service", () => {
});

it("should perform AAD authentication successfully", (done) => {
const verifyAadAuth = function (token: string, callback: any) {
const verifyAadAuth = function(token: string, callback: any) {
const tokenCreds = new TokenCredentials(token, "Bearer");
const aadClient = new BatchServiceClient(tokenCreds, batchEndpoint);
aadClient.account.listSupportedImages(function (err, result, request, response) {
aadClient.account.listSupportedImages(function(err, result, request, response) {
assert.isNull(err);
assert.isDefined(result);
assert.isAtLeast(result!.length, 1);
Expand All @@ -206,7 +214,7 @@ describe("Batch Service", () => {
"https://batch.core.windows.net/",
clientId,
secret,
function (err, tokenResponse) {
function(err, tokenResponse) {
assert.isNull(err);
assert.isDefined(tokenResponse);
assert.isDefined((tokenResponse as TokenResponse).accessToken);
Expand Down Expand Up @@ -368,7 +376,7 @@ describe("Batch Service", () => {
assert.equal(result[0].schedulingState, "enabled");
assert.isTrue(result[0].isDedicated);
assert.equal(result._response.status, 200);
compute_nodes = result.map(function (x) {
compute_nodes = result.map(function(x) {
return x.id!;
});
});
Expand Down Expand Up @@ -418,7 +426,7 @@ describe("Batch Service", () => {
.getRemoteDesktop("nodesdktestpool1", compute_nodes[0])
.then((result) => {
assert.equal(result._response.status, 200);
readStreamToBuffer(result.readableStreamBody!, function (_err, buff) {
readStreamToBuffer(result.readableStreamBody!, function(_err, buff) {
assert.isAtLeast(buff.length, 1);
done();
});
Expand Down Expand Up @@ -496,9 +504,10 @@ describe("Batch Service", () => {
});

it("should evaluate pool autoscale successfully", async () => {
const result = await client.pool.evaluateAutoScale("nodesdktestpool1", {
autoScaleFormula: "$TargetDedicatedNodes=3"
});
const result = await client.pool.evaluateAutoScale(
"nodesdktestpool1",
"$TargetDedicatedNodes=3"
);

assert.equal(
result.results,
Expand All @@ -508,9 +517,7 @@ describe("Batch Service", () => {
});

it("should fail to evaluate invalid autoscale formula", async () => {
const result = await client.pool.evaluateAutoScale("nodesdktestpool1", {
autoScaleFormula: "something_useless"
});
const result = await client.pool.evaluateAutoScale("nodesdktestpool1", "something_useless");

assert.equal(
result.results,
Expand Down Expand Up @@ -557,7 +564,7 @@ describe("Batch Service", () => {

it("should fail to list pools with invalid max", async () => {
const options = { poolListOptions: { maxResults: -5 } };
client.pool.list(options, function (err, result) {
client.pool.list(options, function(err, result) {
assert.equal(
err!.message,
'"options.poolListOptions.maxResults" with value "-5" should satisfy the constraint "InclusiveMinimum": 1.'
Expand Down Expand Up @@ -774,6 +781,7 @@ describe("Batch Service", () => {
assert.equal(result._response.status, 204);
});

// This hangs
deyaaeldeen marked this conversation as resolved.
Show resolved Hide resolved
it("should update a task successfully", async () => {
const options = { constraints: { maxTaskRetryCount: 3 } };
const result = await client.task.update(
Expand Down Expand Up @@ -860,7 +868,7 @@ describe("Batch Service", () => {

assert.equal(result._response.status, 201);

wait(15000);
await wait(20000);
const result2 = await client.task.get(jobId, taskId);

assert.isDefined(result2.userIdentity);
Expand All @@ -874,8 +882,8 @@ describe("Batch Service", () => {
const jobId = "HelloWorldJobNodeSDKTest";
const result = await client.job.getTaskCounts(jobId);

assert.isDefined(result.active);
assert.isDefined(result.completed);
assert.isDefined(result.taskCounts.active);
assert.isDefined(result.taskCounts.completed);
});

it("should list files from task successfully", async () => {
Expand Down Expand Up @@ -903,7 +911,7 @@ describe("Batch Service", () => {
.getFromTask("HelloWorldJobNodeSDKTest", "HelloWorldNodeSDKTestTask2", "stdout.txt")
.then((result) => {
assert.equal(result._response.status, 200);
readStreamToBuffer(result.readableStreamBody!, function (_err, buff) {
readStreamToBuffer(result.readableStreamBody!, function(_err, buff) {
assert.isAtLeast(buff.length, 1);
done();
});
Expand All @@ -927,7 +935,7 @@ describe("Batch Service", () => {
const result = await client.computeNode.list("nodesdktestpool1");

assert.isAtLeast(result.length, 1);
compute_nodes = result.map(function (x) {
compute_nodes = result.map(function(x) {
return x.id!;
});
//wait(100000);
Expand Down Expand Up @@ -963,7 +971,7 @@ describe("Batch Service", () => {
.getFromComputeNode("nodesdktestpool1", compute_nodes[1], "startup/wd/hello.txt")
.then((result) => {
assert.equal(result._response.status, 200);
readStreamToBuffer(result.readableStreamBody!, function (_err, buff) {
readStreamToBuffer(result.readableStreamBody!, function(_err, buff) {
assert.isAtLeast(buff.length, 1);
done();
});
Expand Down Expand Up @@ -1056,9 +1064,7 @@ describe("Batch Service", () => {
});

it("should disable a job successfully", async () => {
const result = await client.job.disable("HelloWorldJobNodeSDKTest", {
disableTasks: "requeue"
});
const result = await client.job.disable("HelloWorldJobNodeSDKTest", "requeue");

assert.equal(result._response.status, 202);
});
Expand Down Expand Up @@ -1114,7 +1120,6 @@ describe("Batch Service", () => {
assert.equal(result._response.status, 200);
});

//TODO: Have the job schedule perform jobs
it("should list jobs from job schedule successfully", async () => {
const result = await client.job.listFromJobSchedule("NodeSDKTestSchedule");

Expand Down Expand Up @@ -1207,6 +1212,12 @@ describe("Batch Service", () => {
assert.equal(result._response.status, 202);
});

it("should delete a third pool successfully", async () => {
const result = await client.pool.deleteMethod("nodesdkinboundendpointpool");

assert.equal(result._response.status, 202);
});

it("should fail to delete a non-existant pool", async () => {
try {
await client.pool.deleteMethod("nodesdktestpool1");
Expand Down