feat: 完成pipi单元测试
This commit is contained in:
parent
d7d39859d2
commit
352e13fd29
9 changed files with 119 additions and 14 deletions
|
@ -55,7 +55,7 @@ public class WebSocPipeLine<TSocket>(TSocket socket, bool isAES) : AbsPipeLine(i
|
|||
);
|
||||
var fileContent = new ProgressStreamContent(fileStream, progress);
|
||||
content.Add(fileContent, "file", Path.GetFileName(filePath));
|
||||
var it = await client.PostAsync(url, content);
|
||||
var it = await client.PostAsync(url + "/UploadPacked", content);
|
||||
if (it.StatusCode != System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
throw new Exception(it.Content.ReadAsStringAsync().Result);
|
||||
|
|
|
@ -5,7 +5,7 @@ public enum SyncMsgType
|
|||
Error = 0,
|
||||
General = 1,
|
||||
Process = 2,
|
||||
DirFilePack = 3
|
||||
// DirFilePack = 3
|
||||
}
|
||||
public enum SyncProcessStep
|
||||
{
|
||||
|
|
|
@ -20,8 +20,12 @@ namespace LocalServer.Controllers
|
|||
if (Factory.GetServerByName(Name) == null)
|
||||
{
|
||||
var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
||||
var pipeLine = new WebSocPipeLine<WebSocket>(webSocket,false);
|
||||
Factory.CreateLocalSyncServer(pipeLine, Name);
|
||||
var pipeLine = new WebSocPipeLine<WebSocket>(webSocket, false);
|
||||
Factory.CreateLocalSyncServer(
|
||||
pipeLine,
|
||||
Name,
|
||||
new WebSocPipeLine<ClientWebSocket>(new ClientWebSocket(), false)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System.Net.WebSockets;
|
||||
using Common;
|
||||
|
||||
namespace LocalServer;
|
||||
|
@ -31,20 +30,19 @@ public class LocalSyncServer
|
|||
/// </summary>
|
||||
public readonly AbsPipeLine LocalPipe;
|
||||
|
||||
public readonly AbsPipeLine RemotePipe = new WebSocPipeLine<ClientWebSocket>(
|
||||
new ClientWebSocket(),false
|
||||
);
|
||||
public readonly AbsPipeLine RemotePipe;
|
||||
/// <summary>
|
||||
/// 父工程,用于释放资源
|
||||
/// </summary>
|
||||
public readonly LocalSyncServerFactory Factory;
|
||||
|
||||
public LocalSyncServer(AbsPipeLine pipe, LocalSyncServerFactory factory,string name)
|
||||
public LocalSyncServer(AbsPipeLine pipe, LocalSyncServerFactory factory,string name,AbsPipeLine remotePipe )
|
||||
{
|
||||
LocalPipe = pipe;
|
||||
Factory = factory;
|
||||
StateHelper = new ConnectAuthorityHelper(this);
|
||||
Name = name;
|
||||
RemotePipe = remotePipe;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
using Common;
|
||||
using System.Net.WebSockets;
|
||||
|
||||
namespace LocalServer;
|
||||
|
||||
public class LocalSyncServerFactory
|
||||
{
|
||||
private readonly object Lock = new();
|
||||
|
||||
public void CreateLocalSyncServer(AbsPipeLine pipeLine,string name)
|
||||
public void CreateLocalSyncServer(AbsPipeLine pipeLine, string name,AbsPipeLine absPipeLine)
|
||||
{
|
||||
var server = new LocalSyncServer(pipeLine, this,name);
|
||||
var server = new LocalSyncServer(
|
||||
pipeLine,
|
||||
this,
|
||||
name,
|
||||
absPipeLine
|
||||
);
|
||||
lock (Lock)
|
||||
{
|
||||
Servers.Add(server);
|
||||
|
@ -26,7 +33,7 @@ public class LocalSyncServerFactory
|
|||
|
||||
public LocalSyncServer? GetServerByName(string name)
|
||||
{
|
||||
var it = Servers.Where(x=>x.Name== name).FirstOrDefault();
|
||||
var it = Servers.Where(x => x.Name == name).FirstOrDefault();
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ using System.Diagnostics;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using Common;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LocalServer;
|
||||
|
||||
|
@ -321,7 +320,7 @@ public class UploadPackedHelper(LocalSyncServer context)
|
|||
{
|
||||
Context
|
||||
.LocalPipe.UploadFile(
|
||||
Context.NotNullSyncConfig.RemoteUrl + "/UploadPacked",
|
||||
Context.NotNullSyncConfig.RemoteUrl ,
|
||||
$"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.zip",
|
||||
(double current) =>
|
||||
{
|
||||
|
|
61
Server/ServerTest/PipeSeed.cs
Normal file
61
Server/ServerTest/PipeSeed.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using Common;
|
||||
using LocalServer;
|
||||
using RemoteServer;
|
||||
|
||||
namespace ServerTest;
|
||||
|
||||
public class PipeSeed : IDisposable
|
||||
{
|
||||
public PipeSeed()
|
||||
{
|
||||
TestConfig = new Config
|
||||
{
|
||||
Name = "Test",
|
||||
RemoteUrl = "D:/FileSyncTest",
|
||||
RemotePwd = "",
|
||||
IsDeployDb = true,
|
||||
IsDeployProject = true,
|
||||
LocalProjectAbsolutePath = "D:/git/HMES-H7-HNFY/HMES-H7-HNFYMF/HMES-H7-HNFYMF.WEB",
|
||||
LocalRootPath = "D:/FileSyncTest/src",
|
||||
|
||||
RemoteRootPath = "D:/FileSyncTest/dst",
|
||||
SrcDb = new MSSqlConfig
|
||||
{
|
||||
ServerName = "172.16.12.2",
|
||||
DatebaseName = "HMES_H7_HNFYMF",
|
||||
User = "hmes-h7",
|
||||
Password = "Hmes-h7666",
|
||||
TrustServerCertificate = "True",
|
||||
SyncTablesData = new List<string>
|
||||
{
|
||||
"dbo.sys_Button",
|
||||
"dbo.sys_Menu",
|
||||
"dbo.sys_Module",
|
||||
"dbo.sys_Page",
|
||||
}
|
||||
},
|
||||
DstDb = new MSSqlConfig
|
||||
{
|
||||
ServerName = "127.0.0.1",
|
||||
DatebaseName = "HMES_H7_HNFYMF",
|
||||
User = "sa",
|
||||
Password = "0",
|
||||
TrustServerCertificate = "True"
|
||||
},
|
||||
DirFileConfigs = new List<DirFileConfig>{
|
||||
new DirFileConfig{
|
||||
DirPath = "/bin",
|
||||
Excludes = ["/roslyn","/Views"]
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Config TestConfig;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
36
Server/ServerTest/PipeTest.cs
Normal file
36
Server/ServerTest/PipeTest.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Text.Json;
|
||||
using Common;
|
||||
using LocalServer;
|
||||
using RemoteServer;
|
||||
using XUnit.Project.Attributes;
|
||||
/*using Newtonsoft.Json;*/
|
||||
|
||||
namespace ServerTest;
|
||||
|
||||
public class PipeTest
|
||||
{
|
||||
[Fact]
|
||||
public async void TestCase()
|
||||
{
|
||||
var p1 = new TestPipe(false);
|
||||
var p2 = new TestPipe(false);
|
||||
p1.Other = p2;
|
||||
p2.Other = p1;
|
||||
var p3 = new TestPipe(true);
|
||||
var p4 = new TestPipe(true);
|
||||
p3.Other = p4;
|
||||
p4.Other = p3;
|
||||
|
||||
var lf = new LocalSyncServerFactory();
|
||||
lf.CreateLocalSyncServer(p2,"Test",p3);
|
||||
var rf = new RemoteSyncServerFactory();
|
||||
rf.CreateRemoteSyncServer(p4,"Test");
|
||||
var starter = new SyncMsg(
|
||||
SyncMsgType.General,
|
||||
SyncProcessStep.Connect,
|
||||
JsonSerializer.Serialize(new PipeSeed().TestConfig)
|
||||
);
|
||||
await p1.SendMsg(starter);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue