Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add testing of FileStream not truncating files when opening fails #24163

Merged
merged 1 commit into from
Oct 3, 2017

Conversation

poizan42
Copy link

@poizan42 poizan42 commented Sep 20, 2017

Test of #24081 (succeeds after dotnet/coreclr#14043)

@poizan42
Copy link
Author

poizan42 commented Sep 20, 2017

Is it overkill to have the test being run by all tests for ctors with FileShare?

@poizan42 poizan42 changed the title Add test for dotnet/corefx#24081 (succeeds after #14043) Add test for #24081 (succeeds after dotnet/coreclr#14043) Sep 20, 2017
@poizan42 poizan42 force-pushed the no-truncate-on-error-test branch from 86dcfbf to 520a686 Compare September 20, 2017 09:21
@poizan42 poizan42 force-pushed the no-truncate-on-error-test branch from 520a686 to abcac7a Compare September 20, 2017 10:43
@karelz
Copy link
Member

karelz commented Sep 20, 2017

@poizan42 thanks for your contribution!
Can you please update the title to describe the change and add description in top post with issue links? (issue numbers in titles are rarely useful - think about someone in future looking at history ;)). Thanks!

I have added you as collaborator, so that we can assign the issue #24081 to you (I assume this is a fix for it in combo with dotnet/coreclr#14043). It is GH limitation for assignments :(.
Please note that it will auto-subscribe you to all repos notifcactions, which is madness of ~500 notifications per day. We recommend everyone to disable them and watch only notifications for your mentions.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test.

using (FileStream reader = CreateFileStream(fileName, FileMode.Open, FileAccess.Read))
{
byte[] buf = new byte[1];
Assert.Equal(1, reader.Read(buf, 0, 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let's also assert that buf[0] == 42

fs.Flush();
try
{
CreateFileStream(fileName, fileMode, FileAccess.Write, FileShare.None).Dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this should use Assert.Throws.

@poizan42 poizan42 changed the title Add test for #24081 (succeeds after dotnet/coreclr#14043) Add testing of FileStream not truncating files when opening fails Sep 20, 2017
@poizan42 poizan42 force-pushed the no-truncate-on-error-test branch from abcac7a to 6ee6fcc Compare September 20, 2017 16:48
@poizan42
Copy link
Author

@stephentoub I have fixed those now

{
fs.Write(new byte[] { 42 }, 0, 1);
fs.Flush();
FSAssert.ThrowsSharingViolation(() => CreateFileStream(fileName, fileMode, FileAccess.Write, FileShare.None).Dispose());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the Dispose shouldn't be necessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if it doesn't throw then we leave the file open until a GC occurs, does that not matter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if it doesn't throw

That's true, but if it doesn't throw, we have bigger problems :) I'm ok with it either way, but in general we haven't worried about such things elsewhere.

Copy link
Contributor

@pjanotti pjanotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @poizan42 LGTM

@pjanotti
Copy link
Contributor

@dotnet-bot test this please

1 similar comment
@stephentoub
Copy link
Member

@dotnet-bot test this please

@stephentoub stephentoub merged commit 819da8a into dotnet:master Oct 3, 2017
@karelz karelz added this to the 2.1.0 milestone Oct 11, 2017
pjanotti pushed a commit to pjanotti/corefx that referenced this pull request Oct 31, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants