AWSSDK.UnitTests.OptimisticLockedFileTest.FileLockedByThisProcess C# (CSharp) Method

FileLockedByThisProcess() public method

This test needs to be run manually since it relies on a race condition and a manual code change. It's been run as part of development but it won't be run in the normal build process. This test makes sure that the OptimisticLockedTextFile.Persist() method locks the file properly while it's being written. To run this test: 1. temporarily add System.Threading.Thread.Sleep(5000); to OptimisticLockedTextFile.Persist() just after the file is opened 2. uncomment the [TestMethod] attribute on this method 3. run the test 4. REVERT YOUR CHANGES FROM STEPS 1 AND 2
public FileLockedByThisProcess ( ) : void
return void
        public void FileLockedByThisProcess()
        {
            using (var tester = new OptimisticLockedTextFileTester(true))
            {
                // start the persist thread
                Thread thread = new Thread(new ThreadStart(() => { tester.TextFile.Persist(); }));
                thread.Start();

                // give it time to open the file
                Thread.Sleep(2000);

                // try something that requires minimal access to the file and make sure the correct exception is thrown
                AssertExtensions.ExpectException(() =>
                {
                    using (File.Open(tester.TextFile.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                    }
                }, typeof(IOException), string.Format(FileLockedMessageFormat, tester.TextFile.FilePath));

                // wait for the persist to complete
                thread.Join();
            }
        }