-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test cases for writing concurrently in web session.
- Loading branch information
1 parent
02abda9
commit e1561b3
Showing
7 changed files
with
226 additions
and
0 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
85 changes: 85 additions & 0 deletions
85
dotnet/test/DotNetCoreWebUnitTest/Middleware/SessionTest.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,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Net.Http.Headers; | ||
using Xunit; | ||
namespace xUnitTesting | ||
{ | ||
public class SessionTest : MiddlewareTest | ||
{ | ||
public SessionTest() : base() | ||
{ | ||
ClassLoader.FindType("apps.createsession", "GeneXus.Programs.apps", "createsession", Assembly.GetExecutingAssembly(), true);//Force loading assembly for append createsession | ||
ClassLoader.FindType("apps.returnsession", "GeneXus.Programs.apps", "returnsession", Assembly.GetExecutingAssembly(), true);//Force loading assembly for saveimage returnsession | ||
server.AllowSynchronousIO = true; | ||
} | ||
//[Fact] | ||
public void TestConcurrentRequest() | ||
{ | ||
HttpClient client = server.CreateClient(); | ||
CreateSession(client).Wait(); | ||
TestSessionGrids(client).Wait(); | ||
|
||
} | ||
CookieHeaderValue SessionCookie; | ||
async Task CreateSession(HttpClient client) | ||
{ | ||
string[] url1 = new string[]{ "rest/apps/createsession?gxid=48796585&Type=C1&Title=Component", | ||
"rest/apps/createsession?gxid=20200694&Type=C3&Title=Component%203", | ||
"rest/apps/createsession?gxid=30382714&Type=C2&Title=Component%202", | ||
"rest/apps/createsession?gxid=9559029&Type=C4&Title=Component%204", | ||
"rest/apps/createsession?gxid=51975664&Type=C5&Title=Component%205"}; | ||
|
||
//Fix sessionID | ||
var c = await client.GetAsync(url1[0]); | ||
string result = await c.Content.ReadAsStringAsync(); | ||
Console.WriteLine(result); | ||
foreach (var header in c.Headers) | ||
{ | ||
if (header.Key == "Set-Cookie") | ||
{ | ||
string cookieValue = header.Value.First(); | ||
string[] cookieValues = cookieValue.Split(';', '='); | ||
SessionCookie = new CookieHeaderValue(cookieValues[0], cookieValues[1]); | ||
client.DefaultRequestHeaders.Add("Cookie", SessionCookie.ToString()); | ||
} | ||
} | ||
List<Task> tasks = new List<Task>(); | ||
foreach (string s1 in url1) | ||
{ | ||
tasks.Add(Task.Run(() => ExecuteGet(client, s1))); | ||
} | ||
|
||
await Task.WhenAll(tasks); | ||
} | ||
async Task ExecuteGet(HttpClient client, string url) | ||
{ | ||
var r = await client.GetAsync(url); | ||
} | ||
async Task ExecuteGetGrid(HttpClient client, string url) | ||
{ | ||
var r = await client.GetAsync(url); | ||
string result = await r.Content.ReadAsStringAsync(); | ||
Assert.Contains(" - type ", result, StringComparison.OrdinalIgnoreCase); | ||
Console.WriteLine(url + ":" + result); | ||
} | ||
async Task TestSessionGrids(HttpClient client) | ||
{ | ||
string[] url2 = new string[] {"rest/apps/returnsession?gxid=48796585&Type=C1&Title=Component%201&start=0&count=30", | ||
"rest/apps/returnsession?gxid=30382714&Type=C2&Title=Component%202&start=0&count=30", | ||
"rest/apps/returnsession?gxid=51975664&Type=C5&Title=Component%205&start=0&count=30", | ||
"rest/apps/returnsession?gxid=9559029&Type=C4&Title=Component%204&start=0&count=30", | ||
"rest/apps/returnsession?gxid=20200694&Type=C3&Title=Component%203&start=0&count=30" }; | ||
List<Task> tasksGrid = new List<Task>(); | ||
foreach (string s1 in url2) | ||
{ | ||
tasksGrid.Add(Task.Run(() => ExecuteGetGrid(client, s1))); | ||
} | ||
await Task.WhenAll(tasksGrid); | ||
} | ||
} | ||
|
||
} |
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,69 @@ | ||
using GeneXus.Application; | ||
using GeneXus.Data.NTier; | ||
using GeneXus.Http; | ||
using GeneXus.Http.Server; | ||
using GeneXus.Procedure; | ||
|
||
namespace GeneXus.Programs.apps | ||
{ | ||
public class createsession : GXWebProcedure | ||
{ | ||
|
||
public createsession() | ||
{ | ||
context = new GxContext(); | ||
DataStoreUtil.LoadDataStores(context); | ||
IsMain = true; | ||
context.SetDefaultTheme("Carmine"); | ||
} | ||
|
||
public createsession(IGxContext context) | ||
{ | ||
this.context = context; | ||
IsMain = false; | ||
} | ||
|
||
public void execute(string gxid, string Type, string title) | ||
{ | ||
initialize(); | ||
executePrivate(gxid, Type, title); | ||
} | ||
|
||
void executePrivate(string gxid, string Type, string Title) | ||
{ | ||
string Gxids = "gxid_" + gxid; | ||
Gxwebsession.Set("GXID_" + gxid + "GXVAR_DATASDT", gxid); | ||
if (string.IsNullOrEmpty(Gxwebsession.Get(Gxids))) | ||
{ | ||
|
||
Gxwebsession.Set(Gxids + "gxvar_Datasdt", $"Reccord 1 - type {Type}"); | ||
Gxwebsession.Set(Gxids + "gxvar_Data1", ""); | ||
Gxwebsession.Set(Gxids + "gxvar_Data2", ""); | ||
Gxwebsession.Set(Gxids, "true"); | ||
} | ||
this.cleanup(); | ||
} | ||
|
||
public override void cleanup() | ||
{ | ||
CloseOpenCursors(); | ||
base.cleanup(); | ||
if (IsMain) | ||
{ | ||
context.CloseConnections(); | ||
} | ||
ExitApp(); | ||
} | ||
|
||
protected void CloseOpenCursors() | ||
{ | ||
} | ||
|
||
public override void initialize() | ||
{ | ||
Gxwebsession = context.GetSession(); | ||
} | ||
private IGxSession Gxwebsession; | ||
} | ||
|
||
} |
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 @@ | ||
<%@ServiceHost Service= "GeneXus.Programs.apps.createsession,apps.createsession" %> |
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,63 @@ | ||
using GeneXus.Application; | ||
using GeneXus.Data.NTier; | ||
using GeneXus.Http; | ||
using GeneXus.Http.Server; | ||
using GeneXus.Procedure; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace GeneXus.Programs.apps | ||
{ | ||
public class returnsession : GXWebProcedure | ||
{ | ||
|
||
public returnsession() | ||
{ | ||
context = new GxContext(); | ||
DataStoreUtil.LoadDataStores(context); | ||
IsMain = true; | ||
context.SetDefaultTheme("Carmine"); | ||
} | ||
|
||
public returnsession(IGxContext context) | ||
{ | ||
this.context = context; | ||
IsMain = false; | ||
} | ||
|
||
public void execute(string gxid, out string result) | ||
{ | ||
initialize(); | ||
executePrivate(gxid, out result); | ||
} | ||
|
||
void executePrivate(string gxid, out string result) | ||
{ | ||
string Gxids = "gxid_" + gxid; | ||
string actual = Gxwebsession.Get(Gxids + "gxvar_Datasdt"); | ||
result = $"{actual},{gxid}"; | ||
this.cleanup(); | ||
} | ||
|
||
public override void cleanup() | ||
{ | ||
CloseOpenCursors(); | ||
base.cleanup(); | ||
if (IsMain) | ||
{ | ||
context.CloseConnections(); | ||
} | ||
ExitApp(); | ||
} | ||
|
||
protected void CloseOpenCursors() | ||
{ | ||
} | ||
|
||
public override void initialize() | ||
{ | ||
Gxwebsession = context.GetSession(); | ||
} | ||
private IGxSession Gxwebsession; | ||
} | ||
|
||
} |
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 @@ | ||
<%@ServiceHost Service= "GeneXus.Programs.apps.returnsession,apps.returnsession" %> |