Beispiel #1
0
        public async Task ExceptionIsThrownWhenTheBlockIsFull(bool useChannelBasedImpl)
        {
            var tcs         = new TaskCompletionSource <object>();
            var actionBlock = ActionBlockSlim.CreateWithAsyncAction <int>(1, n => tcs.Task, capacityLimit: 1, useChannelBasedImpl);

            actionBlock.Post(42);
            Assert.Equal(1, actionBlock.PendingWorkItems);

            Assert.Throws <ActionBlockIsFullException>(() => actionBlock.Post(1));
            Assert.Equal(1, actionBlock.PendingWorkItems);

            tcs.SetResult(null);
            await WaitUntilAsync(() => actionBlock.PendingWorkItems == 0, TimeSpan.FromMilliseconds(1)).WithTimeoutAsync(TimeSpan.FromSeconds(5));

            Assert.Equal(0, actionBlock.PendingWorkItems);

            // This should not fail!
            actionBlock.Post(1);
        }
Beispiel #2
0
        /// <summary>
        /// Creates an instance of <see cref="FrontEndEngineImplementation"/>.
        /// </summary>
        public FrontEndEngineImplementation(
            LoggingContext loggingContext,
            PathTable pathTable,
            IConfiguration configuration,
            IStartupConfiguration startupConfiguration,
            MountsTable mountsTable,
            InputTracker inputTracker,
            SnapshotCollector snapshotCollector,
            DirectoryTranslator directoryTranslator,
            Func <FileContentTable> getFileContentTable,
            int timerUpdatePeriod,
            bool isPartialReuse,
            IEnumerable <IFrontEnd> registeredFrontends)
        {
            Contract.Requires(loggingContext != null);
            Contract.Requires(pathTable != null);
            Contract.Requires(configuration != null);
            Contract.Requires(startupConfiguration != null);
            Contract.Requires(mountsTable != null);
            Contract.Requires(inputTracker != null);
            Contract.Requires(getFileContentTable != null);
            Contract.Requires(registeredFrontends != null);

            m_loggingContext                  = loggingContext;
            PathTable                         = pathTable;
            m_mountsTable                     = mountsTable;
            m_inputTracker                    = inputTracker;
            m_getFileContentTable             = getFileContentTable;
            m_isPartialReuse                  = isPartialReuse;
            m_frontendsEnvironmentRestriction = registeredFrontends.ToDictionary(frontend => frontend.Name, frontEnd => frontEnd.ShouldRestrictBuildParameters);
            m_snapshotCollector               = snapshotCollector;
            GetTimerUpdatePeriod              = timerUpdatePeriod;
            Layout = configuration.Layout;

            if (ShouldUseSpecCache(configuration))
            {
                m_specCache = new FileCombiner(
                    loggingContext,
                    Path.Combine(configuration.Layout.EngineCacheDirectory.ToString(PathTable), SpecCacheFileName),
                    FileCombiner.FileCombinerUsage.SpecFileCache,
                    configuration.FrontEnd.LogStatistics);
            }

            m_allBuildParameters = new ConcurrentDictionary <string, TrackedValue>(OperatingSystemHelper.EnvVarComparer);

            foreach (var kvp in PopulateFromEnvironmentAndApplyOverrides(loggingContext, startupConfiguration.Properties).ToDictionary())
            {
                m_allBuildParameters.TryAdd(kvp.Key, new TrackedValue(kvp.Value, false));
            }

            m_localDiskContentStore = new LocalDiskContentStore(
                loggingContext,
                PathTable,
                m_getFileContentTable(),
                m_inputTracker.FileChangeTracker,
                directoryTranslator,
                vfsCasRoot: configuration.Cache.VfsCasRoot);

            m_localDiskContentStoreConcurrencyLimiter = ActionBlockSlim <MaterializeFileRequest> .CreateWithAsyncAction(
                Environment.ProcessorCount,
                async request =>
            {
                var requestCompletionSource = request.CompletionSource;

                try
                {
                    var materializeResult = await m_localDiskContentStore.TryMaterializeAsync(
                        request.Cache,
                        request.FileRealizationModes,
                        request.Path,
                        request.ContentHash,
                        trackPath: request.TrackPath,
                        recordPathInFileContentTable: request.RecordPathInFileContentTable);

                    requestCompletionSource.SetResult(materializeResult);
                }
                catch (TaskCanceledException)
                {
                    requestCompletionSource.SetCanceled();
                }
                catch (Exception e)
                {
                    requestCompletionSource.SetException(e);
                }
            });
        }