Example #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestOpenWithCreate()
        {
            if (Path.Windows)
            {
                return;
            }
            Log.Info("Test creating a file with O_CREAT");
            FileDescriptor fd = NativeIO.POSIX.Open(new FilePath(TestDir, "testWorkingOpen").
                                                    GetAbsolutePath(), NativeIO.POSIX.OWronly | NativeIO.POSIX.OCreat, 0x1c0);

            NUnit.Framework.Assert.IsNotNull(true);
            Assert.True(fd.Valid());
            FileOutputStream fos = new FileOutputStream(fd);

            fos.Write(Runtime.GetBytesForString("foo"));
            fos.Close();
            NUnit.Framework.Assert.IsFalse(fd.Valid());
            Log.Info("Test exclusive create");
            try
            {
                fd = NativeIO.POSIX.Open(new FilePath(TestDir, "testWorkingOpen").GetAbsolutePath
                                             (), NativeIO.POSIX.OWronly | NativeIO.POSIX.OCreat | NativeIO.POSIX.OExcl, 0x1c0
                                         );
                NUnit.Framework.Assert.Fail("Was able to create existing file with O_EXCL");
            }
            catch (NativeIOException nioe)
            {
                Log.Info("Got expected exception for failed exclusive create", nioe);
                Assert.Equal(Errno.Eexist, nioe.GetErrno());
            }
        }
Example #2
0
 /// <summary>
 /// Test that opens and closes a file 10000 times - this would crash with
 /// "Too many open files" if we leaked fds using this access pattern.
 /// </summary>
 /// <exception cref="System.IO.IOException"/>
 public virtual void TestFDDoesntLeak()
 {
     if (Path.Windows)
     {
         return;
     }
     for (int i = 0; i < 10000; i++)
     {
         FileDescriptor fd = NativeIO.POSIX.Open(new FilePath(TestDir, "testNoFdLeak").GetAbsolutePath
                                                     (), NativeIO.POSIX.OWronly | NativeIO.POSIX.OCreat, 0x1c0);
         NUnit.Framework.Assert.IsNotNull(true);
         Assert.True(fd.Valid());
         FileOutputStream fos = new FileOutputStream(fd);
         fos.Write(Runtime.GetBytesForString("foo"));
         fos.Close();
     }
 }