This project has moved and is read-only. For the latest updates, please go here.
2
Vote

Async Isolated Tests Fail on Mango/WP8

description

I wanted to see if I could reproduce the second part of my issue #16083 and all I had to do was run the Isolated Storage Tests in the latest build of Sterling. However, it doesn't happen every time but it did the first time and then about 7 tries later it also failed. The canceled one happens every time.

Potential Fix

I think I may have found the fix:
return new BinaryWriter(_iso.OpenFile(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite));
Notice the last parameter. According to this SO answer and MSDN, to allow multi-threading you need to provide the FileShare enum:
ReadWrite: Allows subsequent opening of the file for reading or writing. If this flag is not specified, any request to open the file for reading or writing (by this process or another process) will fail until the file is closed.
I did that and have not been able to see the exception thrown anymore, whereas before it would only take a couple tries (even the first).

Not sure if RW is the proper share for Sterling, but I leave that up to you guys.

Original Report

This might be the source of my issues (since I have some async saves that happen concurrently sometimes and they fail "randomly").

TestConcurrentSaveAndLoadWithIndex

Assert.IsTrue failed. Failed concurrent load: Wintellect.Sterling.Exceptions.SterlingIsolatedStorageException: There was an issue accessing isolated storage: Operation not permitted on IsolatedStorageFileStream.. Check the inner exception for details. ---> System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.

   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)

   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, IsolatedStorageFile isf)

   at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path, FileMode mode, FileAccess access)

   at Wintellect.Sterling.IsolatedStorage.IsoStorageHelper.GetWriter(String path)

   at Wintellect.Sterling.IsolatedStorage.IsolatedStorageDriver.Save(Type type, Int32 keyIndex, Byte[] bytes)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type actualType, Type tableType, Object instance, CycleCache cache)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type type, Object instance)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save[T](TestModel instance)

   at Wintellect.Sterling.IsolatedStorage.Test.Database.TestAsync.<>c__DisplayClass14.<TestConcurrentSaveAndLoad>b__11(Object o, DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnRun(Object argument)

   at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadPool.WorkItem.doWork(Object o)

   at System.Threading.Timer.ring()



   at Wintellect.Sterling.IsolatedStorage.IsoStorageHelper.GetWriter(String path)

   at Wintellect.Sterling.IsolatedStorage.IsolatedStorageDriver.Save(Type type, Int32 keyIndex, Byte[] bytes)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type actualType, Type tableType, Object instance, CycleCache cache)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type type, Object instance)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save[T](TestModel instance)

   at Wintellect.Sterling.IsolatedStorage.Test.Database.TestAsync.<>c__DisplayClass14.<TestConcurrentSaveAndLoad>b__11(Object o, DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnRun(Object argument)

   at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadPool.WorkItem.doWork(Object o)

   at System.Threading.Timer.ring()

 - with inner exception: Wintellect.Sterling.Exceptions.SterlingIsolatedStorageException: There was an issue accessing isolated storage: Operation not permitted on IsolatedStorageFileStream.. Check the inner exception for details. ---> System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted on IsolatedStorageFileStream.

   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf)

   at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, IsolatedStorageFile isf)

   at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path, FileMode mode, FileAccess access)

   at Wintellect.Sterling.IsolatedStorage.IsoStorageHelper.GetWriter(String path)

   at Wintellect.Sterling.IsolatedStorage.IsolatedStorageDriver.Save(Type type, Int32 keyIndex, Byte[] bytes)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type actualType, Type tableType, Object instance, CycleCache cache)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type type, Object instance)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save[T](TestModel instance)

   at Wintellect.Sterling.IsolatedStorage.Test.Database.TestAsync.<>c__DisplayClass14.<TestConcurrentSaveAndLoad>b__11(Object o, DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnRun(Object argument)

   at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadPool.WorkItem.doWork(Object o)

   at System.Threading.Timer.ring()



   at Wintellect.Sterling.IsolatedStorage.IsoStorageHelper.GetWriter(String path)

   at Wintellect.Sterling.IsolatedStorage.IsolatedStorageDriver.Save(Type type, Int32 keyIndex, Byte[] bytes)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type actualType, Type tableType, Object instance, CycleCache cache)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save(Type type, Object instance)

   at Wintellect.Sterling.Database.BaseDatabaseInstance.Save[T](TestModel instance)

   at Wintellect.Sterling.IsolatedStorage.Test.Database.TestAsync.<>c__DisplayClass14.<TestConcurrentSaveAndLoad>b__11(Object o, DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)

   at System.ComponentModel.BackgroundWorker.OnRun(Object argument)

   at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ThreadPool.WorkItem.doWork(Object o)

   at System.Threading.Timer.ring()

TestSaveWithCancel

Assert.IsTrue failed. Asynchronous save was not canceled.

comments

kayub wrote Mar 4, 2013 at 2:43 PM

In order to run the tests you will need to update the two Silverlight UT DLLs:

http://www.jeff.wilcox.name/2011/06/updated-ut-mango-bits/

wrote Mar 4, 2013 at 3:42 PM

wrote Mar 5, 2013 at 6:27 PM

kayub wrote Mar 8, 2013 at 12:30 AM

It's a bit early to tell, but since modifying that line in my own build of Sterling, I have not run into the exception during development/testing.