public void TagIsFoundInLog(string message, string tag, bool shouldFind) { bool found = false; var log = new ScanLog(tag, () => found = true); log.Write(message); Assert.Equal(shouldFind, found); }
public void TagIsFoundInSeveralMessages() { bool found = false; var log = new ScanLog("123", () => found = true); log.Write("abc1"); log.Write("2"); log.Write("3cdef"); Assert.True(found); }
private bool ScanSceneParents(string userID, string sceneID, BCEnterpriseContext db) { try { var templist = GetParentsScenes(sceneID, db); var list = templist.Select(x => x.SceneID).ToList(); var scenelist = db.ScanLog.Where(x => list.Contains(x.ObjectID) && x.Type == (int)ScanType.Scene && x.UserID.Equals(userID)).Select(n => n.ObjectID).ToList(); var sc = new List <string>(); sc.Add(sceneID); if (0 < scenelist.Count()) { sc = list.Except(scenelist).ToList(); sc.Distinct(); } if (1 < sc.Count()) { foreach (var scene in sc) { var obj = new ScanLog() { UserID = userID, ObjectID = scene, Type = (int)ScanType.Scene, Time = DBTimeHelper.DBNowTime() }; db.ScanLog.Add(obj); } } else { var obj = new ScanLog() { UserID = userID, ObjectID = sceneID, Type = (int)ScanType.Scene, Time = DBTimeHelper.DBNowTime() }; db.ScanLog.Add(obj); } return(0 < db.SaveChanges()); } catch (Exception e) { throw e; } }
protected async Task <ProcessExecutionResult> RunSimulatorApp( AppBundleInformation appInformation, MlaunchArguments mlaunchArguments, ICrashSnapshotReporter crashReporter, ISimulatorDevice simulator, ISimulatorDevice?companionSimulator, TimeSpan timeout, bool waitForExit, CancellationToken cancellationToken) { _mainLog.WriteLine("System log for the '{1}' simulator is: {0}", simulator.SystemLog, simulator.Name); var simulatorLog = _captureLogFactory.Create( path: Path.Combine(_logs.Directory, simulator.Name + ".log"), systemLogPath: simulator.SystemLog, entireFile: false, LogType.SystemLog); simulatorLog.StartCapture(); _logs.Add(simulatorLog); var simulatorScanToken = await CaptureSimulatorLog(simulator, appInformation, cancellationToken); using var systemLogs = new DisposableList <ICaptureLog> { simulatorLog }; if (companionSimulator != null) { _mainLog.WriteLine("System log for the '{1}' companion simulator is: {0}", companionSimulator.SystemLog, companionSimulator.Name); var companionLog = _captureLogFactory.Create( path: Path.Combine(_logs.Directory, companionSimulator.Name + ".log"), systemLogPath: companionSimulator.SystemLog, entireFile: false, LogType.CompanionSystemLog); companionLog.StartCapture(); _logs.Add(companionLog); systemLogs.Add(companionLog); var companionScanToken = await CaptureSimulatorLog(companionSimulator, appInformation, cancellationToken); if (companionScanToken != null) { simulatorScanToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, companionScanToken.Token); } } await crashReporter.StartCaptureAsync(); _mainLog.WriteLine("Launching the app"); if (waitForExit) { var result = await _processManager.ExecuteCommandAsync(mlaunchArguments, _mainLog, timeout, cancellationToken : cancellationToken); simulatorScanToken?.Cancel(); return(result); } TaskCompletionSource appLaunched = new(); var scanLog = new ScanLog($"Launched {appInformation.BundleIdentifier} with pid", () => { _mainLog.WriteLine("App launch detected"); appLaunched.SetResult(); }); _mainLog.WriteLine("Waiting for the app to launch.."); var runTask = _processManager.ExecuteCommandAsync(mlaunchArguments, Log.CreateAggregatedLog(_mainLog, scanLog), timeout, cancellationToken: cancellationToken); await Task.WhenAny(runTask, appLaunched.Task); if (!appLaunched.Task.IsCompleted) { // In case the other task completes first, it is because one of these scenarios happened: // - The app crashed and never launched // - We missed the launch signal somehow and the app timed out // - The app launched and quit immediately and race condition noticed that before the scan log did its job // In all cases, we should return the result of the run task, it will be most likely 137 + Timeout (killed by us) // If not, it will be a success because the app ran for a super short amount of time _mainLog.WriteLine("App launch was not detected in time"); return(runTask.Result); } _mainLog.WriteLine("Not waiting for the app to exit"); return(new ProcessExecutionResult { ExitCode = 0 }); }