This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix race conditions in BlobWriteStream / OpenWrite (#1038)
* Fix blob write stream releasing lock prematurely. * Fix race conditions in BlobWriteStream. * fix file write stream as well.
- Loading branch information
1 parent
b0d47bf
commit c71fd86
Showing
5 changed files
with
166 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
Test/ClassLibraryCommon/Core/AsyncManualResetEventTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// ----------------------------------------------------------------------------------------- | ||
// <copyright file="AsyncStreamCopierTests.cs" company="Microsoft"> | ||
// Copyright 2013 Microsoft Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
// ----------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Storage.Core.Util; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.Azure.Storage.Core | ||
{ | ||
[TestClass] | ||
public class AsyncManualResetEventTests | ||
{ | ||
[TestMethod] | ||
public void CtorCreateSet() | ||
{ | ||
// arrange | ||
var theEvent = new AsyncManualResetEvent(true); | ||
|
||
// act | ||
bool completed = theEvent.WaitAsync().Wait(TimeSpan.FromSeconds(2)); | ||
|
||
// assert | ||
Assert.IsTrue(completed); | ||
} | ||
|
||
[TestMethod] | ||
public void CtorCreateUnSet() | ||
{ | ||
// arrange | ||
var theEvent = new AsyncManualResetEvent(false); | ||
|
||
// act | ||
bool completed = theEvent.WaitAsync().Wait(TimeSpan.FromSeconds(2)); | ||
|
||
// assert | ||
Assert.IsFalse(completed); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public void ShouldReset(bool initialState) | ||
{ | ||
// arrange | ||
var theEvent = new AsyncManualResetEvent(initialState); | ||
|
||
// act | ||
theEvent.Reset(); | ||
|
||
// assert | ||
bool completed = theEvent.WaitAsync().Wait(TimeSpan.FromSeconds(2)); | ||
Assert.IsFalse(completed); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public async Task ShouldResetAfterSequenceOfTransitions(bool initialState) | ||
{ | ||
// arrange | ||
var theEvent = new AsyncManualResetEvent(initialState); | ||
|
||
// act | ||
await theEvent.Set(); | ||
theEvent.Reset(); | ||
await theEvent.Set(); | ||
theEvent.Reset(); | ||
|
||
// assert | ||
bool completed = theEvent.WaitAsync().Wait(TimeSpan.FromSeconds(2)); | ||
Assert.IsFalse(completed); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public async Task ShouldSet(bool initialState) | ||
{ | ||
// arrange | ||
var theEvent = new AsyncManualResetEvent(initialState); | ||
|
||
// act | ||
await theEvent.Set(); | ||
|
||
// assert | ||
bool completed = theEvent.WaitAsync().Wait(TimeSpan.FromSeconds(2)); | ||
Assert.IsTrue(completed); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(true)] | ||
[DataRow(false)] | ||
public async Task ShouldSetAfterSequenceOfTransitions(bool initialState) | ||
{ | ||
// arrange | ||
var theEvent = new AsyncManualResetEvent(initialState); | ||
|
||
// act | ||
await theEvent.Set(); | ||
theEvent.Reset(); | ||
await theEvent.Set(); | ||
theEvent.Reset(); | ||
await theEvent.Set(); | ||
|
||
// assert | ||
bool completed = theEvent.WaitAsync().Wait(TimeSpan.FromSeconds(2)); | ||
Assert.IsTrue(completed); | ||
} | ||
} | ||
|
||
} |