public void NamedValuesAreExposed() { const string TestServer = "http://*****:*****@" config({{ resolvers: [ {{ kind: 'Download', downloads: [{{ moduleName: 'download', url: '{TestServer}value-test.zip', downloadedValueName: 'theDownloaded', archiveType: 'zip', extractedValueName: 'theExtracted' }}] }}, {{ kind: 'DScript', }} ], mounts: [ {{ name: a`LocalLow`, path: p`Out/Ignore`, trackSourceFileChanges: false, isWritable: true, isReadable: true, }}, ], }});") .AddSpec("package.dsc", @" import * as downloads from 'download'; const d = downloads.theDownloaded; const e = downloads.theExtracted; ") .RootSpec("package.dsc") .EvaluateWithNoErrors(); listener.Stop(); listener.Close(); } }
/// <summary> /// Starts an HTTP server for testing purposes and runs a test in its context /// </summary> protected BuildXLEngineResult StartServerAndRunTest(Func <BuildXLEngineResult> performTest) { using (var listener = new HttpListener()) { // This test relies on the mutex in the build engine to only run one unittest at a time and this assembly to be single thread // if any of those assumptions will be broken we will have to either dynamically (remind you globally) get unique ports. // HttpListner doesn't have this built-in so there will always be a race. Just spam the ports until one doesn't fail // use a global mutex (This is not honored by qtest since it can run in a different session on cloudbuild). listener.Prefixes.Add(TestServer); listener.Start(); TestRequestHandler.StartRequestHandler(listener, m_alternativeDataIndicator, m_webRequestCount); try { return(performTest()); } finally { listener.Stop(); listener.Close(); } } }
private async Task TestDownloadResolver(DownloadData data, Func <DownloadResolver, Task> performTest, bool useHttpServer = true) { var dummyConfigFile = Path.Combine(TemporaryDirectory, m_uniqueTestFolder, "config.dsc"); var statistics = new Statistics(); var moduleRegistry = new ModuleRegistry(FrontEndContext.SymbolTable); var configuration = ConfigurationHelpers.GetDefaultForTesting(FrontEndContext.PathTable, AbsolutePath.Create(FrontEndContext.PathTable, dummyConfigFile)); var resolverSettings = new ResolverSettings(); var frontEndFactory = new FrontEndFactory(); frontEndFactory.AddFrontEnd(new DownloadFrontEnd()); frontEndFactory.TrySeal(new LoggingContext("UnitTest")); using (var host = new FrontEndHostController( frontEndFactory, new EvaluationScheduler(degreeOfParallelism: 1), moduleRegistry, new FrontEndStatistics(), global::BuildXL.FrontEnd.Core.Tracing.Logger.CreateLogger(), collector: null, collectMemoryAsSoonAsPossible: false)) { var frontEndEngineAbstraction = new BasicFrontEndEngineAbstraction( FrontEndContext.PathTable, FrontEndContext.FileSystem, configuration); ((IFrontEndController)host).InitializeHost(FrontEndContext, configuration); host.SetState(frontEndEngineAbstraction, new TestEnv.TestPipGraph(), configuration); var resolver = new DownloadResolver( statistics, host, FrontEndContext, Logger.Log, "TestFrontEnd" ); var workspaceResolver = new DownloadWorkspaceResolver(); workspaceResolver.UpdateDataForDownloadData(data, FrontEndContext); await resolver.InitResolverAsync(resolverSettings, workspaceResolver); if (useHttpServer) { using (var listener = new HttpListener()) { // This test relies on the mutex in the build engine to only run one unittest at a time and this assembly to be single thread // if any of those assumptions will be broken we will have to either dynamically (remind you globally) get unique ports. // HttpListner doesn't have this built-in so there will always be a race. Just spam the ports utnill one doesn't fail // use a global mutex (This is not honored by qtest since it can run in a different session on cloudbuild). listener.Prefixes.Add(TestServer); listener.Start(); TestRequestHandler.StartRequestHandler(listener, m_alternativeDataIndicator, m_webRequestCount); await performTest(resolver); listener.Stop(); listener.Close(); } } else { await performTest(resolver); } } }