Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Use relaxed JavascriptEncoder in S.T.JSON specific tests to improve coverage.#39560

Merged
ahsonkhan merged 6 commits intodotnet:masterfrom
ahsonkhan:UseRelaxedEscaper
Jul 29, 2019
Merged

Use relaxed JavascriptEncoder in S.T.JSON specific tests to improve coverage.#39560
ahsonkhan merged 6 commits intodotnet:masterfrom
ahsonkhan:UseRelaxedEscaper

Conversation

@ahsonkhan
Copy link

@ahsonkhan ahsonkhan added test enhancement Improvements of test source code area-System.Text.Json labels Jul 17, 2019
@ahsonkhan ahsonkhan added this to the 3.0 milestone Jul 17, 2019
@ahsonkhan ahsonkhan self-assigned this Jul 17, 2019
var ms = new MemoryStream();
TextWriter streamWriter = new StreamWriter(ms, new UTF8Encoding(false), 1024, true);

var json = new JsonTextWriter(streamWriter)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should discuss whether this is the best way to get expected strings going forward. Seems to work by coincidence in this case (same escaping rules). In other cases we have started to diverge (e.g. casing).

@ahsonkhan
Copy link
Author

Any other feedback?

Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
};

using var writer = new Utf8JsonWriter(buffer, options);
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I vastly prefer "block statement using". This using ends after AssertContents, but following the least-need principle the using should end after (or instead-of) writer.Flush. (The new using statement is particularly bad in async methods, where it can make the using straddle an await it didn't need to)

So, replacing all of the usings with scoped blocks would make me happier, but it's not critical.

@ericstj
Copy link
Member

ericstj commented Jul 25, 2019

@ahsonkhan are you planning to get this one in?

@ahsonkhan ahsonkhan added the auto-merge Automatically merge PR once CI passes. label Jul 29, 2019
@ghost
Copy link

ghost commented Jul 29, 2019

Hello @ahsonkhan!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ahsonkhan
Copy link
Author

Test failure is unrelated:
https://mc.dot.net/#/user/dotnet-bot/pr~2Fdotnet~2Fcorefx~2Frefs~2Fpull~2F39560~2Fmerge/test~2Ffunctional~2Fcli~2F~2F/20190728.25/workItem/System.Net.Http.Functional.Tests/analysis/xunit/System.Net.Http.Functional.Tests.SocketsHttpHandlerTest_Http2~2FHttp2_PendingReceive_SendsReset(doRead:%20True)
System.Net.Http.Functional.Tests.SocketsHttpHandlerTest_Http2/Http2_PendingReceive_SendsReset(doRead: True)

Message :
System.IO.IOException : Unable to read data from the transport connection: Broken pipe.
---- System.Net.Sockets.SocketException : Broken pipe
Stack Trace :
   at System.Net.Security.SslStream.<WriteSingleChunk>g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn) in /_/src/System.Net.Security/src/System/Net/Security/SslStream.Implementation.cs:line 1271
   at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer) in /_/src/System.Net.Security/src/System/Net/Security/SslStream.Implementation.cs:line 1521
   at System.Net.Test.Common.Http2LoopbackConnection.WriteFrameAsync(Frame frame) in /_/src/Common/tests/System/Net/Http/Http2LoopbackConnection.cs:line 87
   at System.Net.Http.Functional.Tests.HttpClientHandlerTest_Http2.<>c__DisplayClass62_0.<<Http2_PendingReceive_SendsReset>b__1>d.MoveNext() in /_/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs:line 1784
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.Tasks.TaskTimeoutExtensions.WhenAllOrAnyFailed(Task[] tasks) in /_/src/Common/tests/System/Threading/Tasks/TaskTimeoutExtensions.cs:line 83
   at System.Threading.Tasks.TaskTimeoutExtensions.WhenAllOrAnyFailed(Task[] tasks) in /_/src/Common/tests/System/Threading/Tasks/TaskTimeoutExtensions.cs:line 111
   at System.Threading.Tasks.TaskTimeoutExtensions.WhenAllOrAnyFailed(Task[] tasks, Int32 millisecondsTimeout) in /_/src/Common/tests/System/Threading/Tasks/TaskTimeoutExtensions.cs:line 71
   at System.Net.Test.Common.Http2LoopbackServer.CreateClientAndServerAsync(Func`2 clientFunc, Func`2 serverFunc, Int32 timeout) in /_/src/Common/tests/System/Net/Http/Http2LoopbackServer.cs:line 186
   at System.Net.Http.Functional.Tests.HttpClientHandlerTest_Http2.Http2_PendingReceive_SendsReset(Boolean doRead) in /_/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Http2.cs:line 1736
--- End of stack trace from previous location where exception was thrown ---
----- Inner Stack Trace -----

@ahsonkhan ahsonkhan merged commit 74d26be into dotnet:master Jul 29, 2019
@ahsonkhan ahsonkhan deleted the UseRelaxedEscaper branch July 29, 2019 04:17
ahsonkhan added a commit to ahsonkhan/corefx that referenced this pull request Jul 29, 2019
…overage. (dotnet#39560)

* Use relaxed JavascriptEncoder in S.T.JSON specific tests to improve
coverage.

* Add control characters as well as part of the test data.

* Add JsonElement.WriteTo test and make sure all Utf8JsonWriter in tests
are disposed.

* Fix spacing/formatting.

* Fix call to AssertEquals since it moved to JsonTestHelper.
ahsonkhan added a commit that referenced this pull request Jul 29, 2019
…overage. (#39560) (#39850)

* Use relaxed JavascriptEncoder in S.T.JSON specific tests to improve
coverage.

* Add control characters as well as part of the test data.

* Add JsonElement.WriteTo test and make sure all Utf8JsonWriter in tests
are disposed.

* Fix spacing/formatting.

* Fix call to AssertEquals since it moved to JsonTestHelper.
@karelz karelz removed the test enhancement Improvements of test source code label Aug 3, 2019
@karelz karelz modified the milestones: 3.0, 5.0 Aug 3, 2019
@karelz
Copy link
Member

karelz commented Aug 3, 2019

@ahsonkhan this specific PR went into master after last integration to release/3.0 branch, so I fixed milestone to 5.0.
It seems it was ported to 3.0 in #39850.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…overage. (dotnet/corefx#39560)

* Use relaxed JavascriptEncoder in S.T.JSON specific tests to improve
coverage.

* Add control characters as well as part of the test data.

* Add JsonElement.WriteTo test and make sure all Utf8JsonWriter in tests
are disposed.

* Fix spacing/formatting.

* Fix call to AssertEquals since it moved to JsonTestHelper.


Commit migrated from dotnet/corefx@74d26be
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Text.Json auto-merge Automatically merge PR once CI passes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants