Skip to content

Commit fe0fa0e

Browse files
committed
adding first wave of e2e tests
1 parent 032b944 commit fe0fa0e

File tree

116 files changed

+2938
-1234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2938
-1234
lines changed

src/WebJobs.Script.WebHost/Controllers/HostController.cs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
using System.Collections.Generic;
55
using System.Collections.ObjectModel;
66
using System.Diagnostics;
7-
using System.IO;
8-
using System.IO.Compression;
9-
using System.Linq;
10-
using System.Net;
117
using System.Net.Http;
128
using System.Threading;
139
using System.Threading.Tasks;
1410
using Microsoft.AspNetCore.Authorization;
1511
using Microsoft.AspNetCore.Http;
1612
using Microsoft.AspNetCore.Mvc;
17-
using Microsoft.AspNetCore.Mvc.Filters;
1813
using Microsoft.AspNetCore.Mvc.WebApiCompatShim;
1914
using Microsoft.Azure.WebJobs.Host;
20-
using Microsoft.Azure.WebJobs.Script.Config;
21-
using Microsoft.Azure.WebJobs.Script.Description;
2215
using Microsoft.Azure.WebJobs.Script.WebHost.Authentication;
2316
using Microsoft.Azure.WebJobs.Script.WebHost.Filters;
2417
using Microsoft.Azure.WebJobs.Script.WebHost.Models;
@@ -47,62 +40,6 @@ public HostController(WebScriptHostManager scriptHostManager, WebHostSettings we
4740
_authorizationService = authorizationService;
4841
}
4942

50-
[HttpPost]
51-
[Route("admin/functions/{name}")]
52-
[Authorize(Policy = PolicyNames.AdminAuthLevel)]
53-
[RequiresRunningHost]
54-
[EnableDebugMode]
55-
public IActionResult Invoke(string name, [FromBody] FunctionInvocation invocation)
56-
{
57-
if (invocation == null)
58-
{
59-
return BadRequest();
60-
}
61-
62-
FunctionDescriptor function = _scriptHostManager.Instance.GetFunctionOrNull(name);
63-
if (function == null)
64-
{
65-
return NotFound();
66-
}
67-
68-
ParameterDescriptor inputParameter = function.Parameters.First(p => p.IsTrigger);
69-
Dictionary<string, object> arguments = new Dictionary<string, object>()
70-
{
71-
{ inputParameter.Name, invocation.Input }
72-
};
73-
Task.Run(() => _scriptHostManager.Instance.CallAsync(function.Name, arguments));
74-
75-
return Accepted();
76-
}
77-
78-
[HttpGet]
79-
[Route("admin/functions/{name}/status")]
80-
[Authorize(Policy = PolicyNames.AdminAuthLevel)]
81-
[RequiresRunningHost]
82-
public IActionResult GetFunctionStatus(string name)
83-
{
84-
FunctionStatus status = new FunctionStatus();
85-
Collection<string> functionErrors = null;
86-
87-
// first see if the function has any errors
88-
if (_scriptHostManager.Instance.FunctionErrors.TryGetValue(name, out functionErrors))
89-
{
90-
status.Errors = functionErrors;
91-
}
92-
else
93-
{
94-
// if we don't have any errors registered, make sure the function exists
95-
// before returning empty errors
96-
FunctionDescriptor function = _scriptHostManager.Instance.Functions.FirstOrDefault(p => p.Name.ToLowerInvariant() == name.ToLowerInvariant());
97-
if (function == null)
98-
{
99-
return NotFound();
100-
}
101-
}
102-
103-
return Ok(status);
104-
}
105-
10643
[HttpGet]
10744
[Route("admin/host/status")]
10845
[Authorize(Policy = PolicyNames.AdminAuthLevelOrInternal)]

src/WebJobs.Script/Rpc/LanguageWorkerChannel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ internal void HandleWorkerError(Exception exc)
321321
link.Dispose();
322322
}
323323

324-
_logger.LogError($"Worker encountered an error.", exc);
324+
_logger.LogError(exc, $"Worker encountered an error.");
325325
_eventManager.Publish(new WorkerErrorEvent(this, exc));
326326
}
327327

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace Microsoft.Azure.WebJobs.Script.Tests.CosmosDBTrigger
8+
{
9+
public class CosmosDBTriggerCSharpEndToEndTests :
10+
CosmosDBTriggerEndToEndTestsBase<CosmosDBTriggerCSharpEndToEndTests.TestFixture>
11+
{
12+
public CosmosDBTriggerCSharpEndToEndTests(TestFixture fixture) : base(fixture)
13+
{
14+
}
15+
16+
[Fact]
17+
public Task CosmosDBTrigger()
18+
{
19+
return CosmosDBTriggerToBlobTest();
20+
}
21+
22+
public class TestFixture : CosmosDBTriggerTestFixture
23+
{
24+
private const string ScriptRoot = @"TestScripts\CSharp";
25+
26+
public TestFixture() : base(ScriptRoot, "csharp")
27+
{
28+
}
29+
}
30+
}
31+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using Microsoft.Azure.Documents;
9+
using Microsoft.Azure.Documents.Client;
10+
using Microsoft.Azure.WebJobs.Host;
11+
using Xunit;
12+
13+
namespace Microsoft.Azure.WebJobs.Script.Tests.CosmosDBTrigger
14+
{
15+
public abstract class CosmosDBTriggerEndToEndTestsBase<TTestFixture> :
16+
EndToEndTestsBase<TTestFixture> where TTestFixture : CosmosDBTriggerTestFixture, new()
17+
{
18+
public CosmosDBTriggerEndToEndTestsBase(TTestFixture fixture) : base(fixture)
19+
{
20+
}
21+
22+
protected async Task CosmosDBTriggerToBlobTest()
23+
{
24+
// CosmosDB tests need the following environment vars:
25+
// "AzureWebJobsCosmosDBConnectionString" -- the connection string to the account
26+
27+
// Waiting for the Processor to acquire leases
28+
await Task.Delay(10000);
29+
30+
await Fixture.InitializeDocumentClient();
31+
bool collectionsCreated = await Fixture.CreateDocumentCollections();
32+
var resultBlob = Fixture.TestOutputContainer.GetBlockBlobReference("cosmosdbtriggere2e-completed");
33+
await resultBlob.DeleteIfExistsAsync();
34+
35+
string id = Guid.NewGuid().ToString();
36+
37+
Document documentToTest = new Document()
38+
{
39+
Id = id
40+
};
41+
42+
await Fixture.DocumentClient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("ItemDb", "ItemCollection"), documentToTest);
43+
44+
// now wait for function to be invoked
45+
string result = await TestHelpers.WaitForBlobAndGetStringAsync(resultBlob,
46+
() => string.Join(Environment.NewLine, Fixture.Host.GetLogMessages()));
47+
48+
if (collectionsCreated)
49+
{
50+
// cleanup collections
51+
await Fixture.DeleteDocumentCollections();
52+
}
53+
54+
Assert.False(string.IsNullOrEmpty(result));
55+
}
56+
}
57+
58+
public abstract class CosmosDBTriggerTestFixture : EndToEndTestFixture
59+
{
60+
protected CosmosDBTriggerTestFixture(string rootPath, string testId) : base(rootPath, testId)
61+
{
62+
}
63+
64+
public DocumentClient DocumentClient { get; private set; }
65+
66+
protected override IEnumerable<string> GetActiveFunctions() => new[] { "CosmosDBTrigger" };
67+
68+
public async Task InitializeDocumentClient()
69+
{
70+
if (DocumentClient == null)
71+
{
72+
var builder = new System.Data.Common.DbConnectionStringBuilder();
73+
builder.ConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString("AzureWebJobsDocumentDBConnectionString");
74+
var serviceUri = new Uri(builder["AccountEndpoint"].ToString());
75+
76+
DocumentClient = new DocumentClient(serviceUri, builder["AccountKey"].ToString());
77+
await DocumentClient.OpenAsync();
78+
}
79+
}
80+
81+
public async Task<bool> CreateDocumentCollections()
82+
{
83+
bool willCreateCollection = false;
84+
Database db = new Database() { Id = "ItemDb" };
85+
await DocumentClient.CreateDatabaseIfNotExistsAsync(db);
86+
Uri dbUri = UriFactory.CreateDatabaseUri(db.Id);
87+
88+
DocumentCollection collection = new DocumentCollection() { Id = "ItemCollection" };
89+
willCreateCollection = !DocumentClient.CreateDocumentCollectionQuery(dbUri).Where(x => x.Id == collection.Id).ToList().Any();
90+
await DocumentClient.CreateDocumentCollectionIfNotExistsAsync(dbUri, collection,
91+
new RequestOptions()
92+
{
93+
OfferThroughput = 400
94+
});
95+
96+
Documents.DocumentCollection leasesCollection = new Documents.DocumentCollection() { Id = "leases" };
97+
await DocumentClient.CreateDocumentCollectionIfNotExistsAsync(dbUri, leasesCollection,
98+
new RequestOptions()
99+
{
100+
OfferThroughput = 400
101+
});
102+
103+
return willCreateCollection;
104+
}
105+
106+
public async Task DeleteDocumentCollections()
107+
{
108+
Uri collectionsUri = UriFactory.CreateDocumentCollectionUri("ItemDb", "ItemCollection");
109+
Uri leasesCollectionsUri = UriFactory.CreateDocumentCollectionUri("ItemDb", "leases");
110+
await DocumentClient.DeleteDocumentCollectionAsync(collectionsUri);
111+
await DocumentClient.DeleteDocumentCollectionAsync(leasesCollectionsUri);
112+
}
113+
114+
public override void Dispose()
115+
{
116+
base.Dispose();
117+
DocumentClient?.Dispose();
118+
}
119+
}
120+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace Microsoft.Azure.WebJobs.Script.Tests.CosmosDBTrigger
8+
{
9+
public class CosmosDBTriggerNodeEndToEndTests :
10+
CosmosDBTriggerEndToEndTestsBase<CosmosDBTriggerNodeEndToEndTests.TestFixture>
11+
{
12+
public CosmosDBTriggerNodeEndToEndTests(TestFixture fixture) : base(fixture)
13+
{
14+
}
15+
16+
[Fact(Skip = "Non-.NET CosmosDBTrigger not currently supported")]
17+
public Task CosmosDBTrigger()
18+
{
19+
return CosmosDBTriggerToBlobTest();
20+
}
21+
22+
public class TestFixture : CosmosDBTriggerTestFixture
23+
{
24+
private const string ScriptRoot = @"TestScripts\Node";
25+
26+
public TestFixture() : base(ScriptRoot, "node")
27+
{
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)