Ejemplo n.º 1
0
        public void ExitOnChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"--exit-on-change -- {scenario.StatusFile} --no-exit");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Change a file
                var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                var programCs    = File.ReadAllText(fileToChange);
                File.WriteAllText(fileToChange, programCs);

                Waiters.WaitForProcessToStop(
                    scenario.WatcherProcess.Id,
                    _defaultTimeout,
                    expectedToStop: true,
                    errorMessage: "The watcher did not stop");

                // Check that the first child process is no longer running
                var ids            = File.ReadAllLines(scenario.StatusFile);
                var firstProcessId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    firstProcessId,
                    TimeSpan.FromSeconds(1),
                    expectedToStop: true,
                    errorMessage: $"PID: {firstProcessId} is still alive");
            }
        }
 private void WatcherEvent(object sender, string file)
 {
     if (file.Equals(_expectedFile, StringComparison.Ordinal))
     {
         Waiters.WaitForFileToBeReadable(_expectedFile, TimeSpan.FromSeconds(10));
         _changed?.Set();
     }
 }
Ejemplo n.º 3
0
            public void Start()
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(StartedFile))
                {
                    RunDotNetWatch(StatusFile, Path.Combine(_scenario.WorkFolder, TestAppName));

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {StartedFile}");
                }

                Waiters.WaitForFileToBeReadable(StartedFile, _defaultTimeout);
            }
Ejemplo n.º 4
0
        public void RestartProcessThatTerminatesAfterFileChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"run {scenario.StatusFile}");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Then wait for the app to exit
                Waiters.WaitForFileToBeReadable(scenario.StartedFile, _defaultTimeout);
                var ids    = File.ReadAllLines(scenario.StatusFile);
                var procId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    procId,
                    _defaultTimeout,
                    expectedToStop: true,
                    errorMessage: "Test app did not exit");

                // Then wait for it to restart when we change a file
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    // On Unix the file write time is in 1s increments;
                    // if we don't wait, there's a chance that the polling
                    // watcher will not detect the change
                    Thread.Sleep(1000);

                    var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                    var programCs    = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
            }
        }
Ejemplo n.º 5
0
        public void ChangeExcludedFile()
        {
            using (var scenario = new GlobbingAppScenario())
            {
                scenario.Start();

                var ids    = File.ReadAllLines(scenario.StatusFile);
                var procId = int.Parse(ids[0]);

                var changedFile = Path.Combine(scenario.TestAppFolder, "exclude", "Baz.cs");
                File.WriteAllText(changedFile, "");

                Console.WriteLine($"Waiting {_negativeTestWaitTime.TotalSeconds} seconds to see if the app restarts");
                Waiters.WaitForProcessToStop(
                    procId,
                    _negativeTestWaitTime,
                    expectedToStop: false,
                    errorMessage: "Test app restarted");
            }
        }
Ejemplo n.º 6
0
        // Add a file that's in a included folder but not matching the globbing pattern
        private void ChangeNonCompiledFile(bool usePollingWatcher)
        {
            using (var scenario = new GlobbingAppScenario())
            {
                scenario.UsePollingWatcher = usePollingWatcher;

                scenario.Start();

                var ids    = File.ReadAllLines(scenario.StatusFile);
                var procId = int.Parse(ids[0]);

                var changedFile = Path.Combine(scenario.TestAppFolder, "include", "not_compiled.css");
                File.WriteAllText(changedFile, "");

                Console.WriteLine($"Waiting {_negativeTestWaitTime.TotalSeconds} seconds to see if the app restarts");
                Waiters.WaitForProcessToStop(
                    procId,
                    _negativeTestWaitTime,
                    expectedToStop: false,
                    errorMessage: "Test app restarted");
            }
        }
Ejemplo n.º 7
0
        public void RestartProcessOnFileChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"run {scenario.StatusFile} --no-exit");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Then wait for it to restart when we change a file
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                    var programCs    = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }

                // Check that the first child process is no longer running
                Waiters.WaitForFileToBeReadable(scenario.StatusFile, _defaultTimeout);
                var ids            = File.ReadAllLines(scenario.StatusFile);
                var firstProcessId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    firstProcessId,
                    TimeSpan.FromSeconds(1),
                    expectedToStop: true,
                    errorMessage: $"PID: {firstProcessId} is still alive");
            }
        }