Skip to content

Commit fd93f2d

Browse files
committed
重新提交
0 parents  commit fd93f2d

70 files changed

Lines changed: 12289 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 4150 additions & 0 deletions
Large diffs are not rendered by default.

.gitattributes

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
name: Build + Release (.NET Framework 4.6.2)
11+
runs-on: windows-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0 # 必须拉取完整历史,否则 git describe 无法正常工作
18+
19+
- name: Setup MSBuild
20+
uses: microsoft/setup-msbuild@v2
21+
with:
22+
vs-version: 'latest'
23+
24+
- name: Restore NuGet packages
25+
run: nuget restore DNet.sln
26+
27+
- name: Build solution
28+
run: msbuild DNet.sln /p:Configuration=Release
29+
30+
- name: Zip release output
31+
run: |
32+
mkdir output
33+
Copy-Item -Recurse -Path DNET\bin\Release\* -Destination output
34+
Compress-Archive -Path output\* -DestinationPath DNET-Build.zip
35+
36+
- name: Upload Release Artifact
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: DNET-Release-Zip
40+
path: DNET-Build.zip
41+
42+
- name: Generate changelog
43+
id: changelog
44+
shell: pwsh
45+
run: |
46+
$tags = git tag --sort=-creatordate
47+
if ($tags.Count -eq 0) {
48+
Write-Host "没有 tag,使用全部提交"
49+
$log = git log --pretty=format:"%h %s"
50+
} elseif ($tags.Count -eq 1) {
51+
$lastTag = $tags[0]
52+
Write-Host "只有一个 tag:$lastTag,显示该 tag 提交"
53+
$log = git log -1 --pretty=format:"%h %s" $lastTag
54+
} else {
55+
$lastTag = $tags[0]
56+
$prevTag = $tags[1]
57+
Write-Host "当前 tag:$lastTag,之前 tag:$prevTag"
58+
$log = git log --pretty=format:"%h %s" "$prevTag..$lastTag"
59+
}
60+
61+
if (-not $log) {
62+
Write-Host "无提交,改为最近5条提交"
63+
$log = git log -n 5 --pretty=format:"%h %s"
64+
}
65+
66+
Write-Host "----- changelog start -----"
67+
Write-Host $log
68+
Write-Host "----- changelog end -----"
69+
70+
Add-Content -Path $env:GITHUB_OUTPUT -Value "changelog<<EOF"
71+
$log.Split("`n") | ForEach-Object { Add-Content -Path $env:GITHUB_OUTPUT -Value $_ }
72+
Add-Content -Path $env:GITHUB_OUTPUT -Value "EOF"
73+
74+
# 🔽 发布 Release 并附带变更日志
75+
- name: Publish GitHub Release
76+
uses: softprops/action-gh-release@v2
77+
with:
78+
files: DNET-Build.zip
79+
body: |
80+
🚀 自动发布版本
81+
82+
📦 变更内容:
83+
${{ steps.changelog.outputs.changelog }}
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/build.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
build:
11+
name: Build and Test (.NET Framework 4.6.2)
12+
runs-on: windows-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup MSBuild
19+
uses: microsoft/setup-msbuild@v2
20+
with:
21+
vs-version: "latest"
22+
23+
- name: Restore NuGet packages
24+
run: nuget restore DNet.sln
25+
26+
- name: Build solution
27+
run: msbuild DNet.sln /p:Configuration=Release
28+
29+
- name: Run NUnit Tests
30+
shell: pwsh
31+
run: |
32+
$testDll = "DNET.Test\bin\Release\DNET.Test.dll"
33+
if (-Not (Test-Path $testDll)) {
34+
Write-Error "Test DLL not found: $testDll"
35+
exit 1
36+
}
37+
38+
# 查找 vstest.console.exe,只取第一条结果
39+
$vsTestPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" `
40+
-latest -products * -requires Microsoft.VisualStudio.PackageGroup.TestTools.Core `
41+
-find **\vstest.console.exe | Select-Object -First 1
42+
43+
if (-not (Test-Path $vsTestPath)) {
44+
Write-Error "vstest.console.exe not found at: $vsTestPath"
45+
exit 1
46+
}
47+
48+
& "$vsTestPath" "$testDll"

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Build results
2+
[Dd]ebug/
3+
[Rr]elease/
4+
x64/
5+
x86/
6+
build/
7+
[Bb]in/
8+
[Oo]bj/
9+
10+
# Visual Studio 2015+ cache/options directory
11+
.vs/
12+
13+
# User-specific files
14+
*.user
15+
*.suo
16+
*.userosscache
17+
*.sln.docstates
18+
19+
# Auto-generated files by Visual Studio
20+
*.vcxproj.user
21+
*.filters
22+
*.log
23+
24+
# NuGet packages
25+
*.nupkg
26+
packages/
27+
# NuGet v3's project.json files
28+
project.lock.json
29+
project.fragment.lock.json
30+
artifacts/
31+
32+
# Visual Studio Code workspace settings
33+
.vscode/
34+
35+
# Rider
36+
.idea/
37+
38+
# Others
39+
*.dbmdl
40+
*.pdb
41+
*.cache
42+
*.ilk
43+
*.meta
44+
*.obj
45+
*.exe
46+
*.dll
47+
*.lib
48+
*.app
49+
*.apk
50+
*.iobj
51+
*.ipdb
52+
*.iuser
53+
*.ipch
54+
*.idb
55+
*.class
56+
*.jar
57+
*.war
58+
*.ear
59+
60+
# DotCover
61+
*.dotCover
62+
63+
# Resharper
64+
_ReSharper*/
65+
66+
# TFS
67+
$tf/
68+
69+
# MSTest test Results
70+
[Tt]est[Rr]esult*/
71+
[Bb]uild[Ll]og.*
72+
73+
# Backup & report files
74+
*.bak
75+
*.backup
76+
*.log
77+
*.rdlc
78+
*.trx
79+
80+
# Others
81+
*.userprefs
82+
83+
# IIS Express
84+
/.vs/
85+
*.vspscc
86+
87+
# Publish Web Output
88+
*.Publish.xml
89+
*.azurePubxml
90+
*.pubxml.user
91+
92+
# Web workbench config files
93+
.sass-cache/
94+
*.css.map
95+
96+
# npm packages
97+
node_modules/
98+
99+
# Yarn Integrity file
100+
.yarn-integrity
101+
102+
# JetBrains Rider
103+
.idea/
104+
.DS_Store

DNET.Test/ByteBufferPoolTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Threading.Tasks;
4+
using NUnit.Framework;
5+
6+
namespace DNET.Test
7+
{
8+
[TestFixture]
9+
public class ByteBufferPoolTests
10+
{
11+
[Test]
12+
public void MultiThread_GetAndRecycle_ShouldBeThreadSafe()
13+
{
14+
int threadCount = 16;
15+
int iterationsPerThread = 100_000;
16+
int blockSize = 256;
17+
int capacityLimit = 128;
18+
19+
ByteBufferPool pool = new ByteBufferPool(blockSize, capacityLimit);
20+
21+
// 用于记录是否出异常
22+
var exceptions = new ConcurrentQueue<Exception>();
23+
24+
Parallel.For(0, threadCount, t => {
25+
try {
26+
for (int i = 0; i < iterationsPerThread; i++) {
27+
// 模拟不同大小的请求
28+
int size = i % 4 == 0 ? blockSize * 2 : blockSize;
29+
30+
ByteBuffer buf = pool.Get(size);
31+
32+
Assert.That(buf.Length, Is.EqualTo(0)); // 重点检查这里
33+
Assert.That(buf.Capacity, Is.GreaterThanOrEqualTo(size));
34+
35+
// 模拟写入
36+
buf.Write(new byte[16], 0, 16);
37+
Assert.That(buf.Length, Is.EqualTo(16)); // 重点检查这里
38+
39+
// 模拟使用后归还
40+
pool.Recycle(buf);
41+
}
42+
} catch (Exception ex) {
43+
exceptions.Enqueue(ex);
44+
}
45+
});
46+
47+
// 所有线程完成后检查
48+
Assert.That(exceptions, Is.Empty, $"有异常发生: {string.Join("\n", exceptions)}");
49+
50+
// 检查分配数量是否合理 LogProxy.LogDebug
51+
Console.WriteLine($"池中剩余数量: {pool.InPoolCount}, 总共分配: {pool.TotalAllocated},成功复用次数: {pool.ReusedCount}");
52+
53+
Assert.That(pool.InPoolCount, Is.LessThanOrEqualTo(capacityLimit), "池中数量不能超过上限");
54+
Assert.That(pool.TotalAllocated, Is.GreaterThan(0), "应至少分配过一次");
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)