Skip to content

Commit

Permalink
Merge pull request #117 from zanecop/master
Browse files Browse the repository at this point in the history
GitHub Actions integration
  • Loading branch information
miwarnec committed Nov 10, 2023
2 parents 553b734 + 4227cc7 commit 0a06fe7
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 17 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,41 @@
# This is a basic workflow to help you get started with Actions
name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: windows-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Build with dotnet
run: dotnet build
--configuration Release
- name: Test with dotnet
run: dotnet test Telepathy.Tests\Telepathy.Tests.csproj
- name: Run load test for one minute
shell: cmd
run: |
cd LoadTest\bin\Release\net471
LoadTest.exe timed 6565 60
echo Ended Load Test
- name: Upload a Build Artifact
uses: actions/upload-artifact@v2.2.4
with:
# Artifact name
name: TelepathyRelease # optional, default is artifact
# A file, directory or wildcard pattern that describes what to upload
path: Telepathy\bin\Release\
# The desired behavior if no files are found using the provided path.


26 changes: 19 additions & 7 deletions LoadTest/Main.cs
Expand Up @@ -9,7 +9,7 @@ public static void Main(string[] args)
{
if (args.Length == 0)
{
Both();
Both(args);
}
else if (args[0] == "server")
{
Expand All @@ -19,30 +19,42 @@ public static void Main(string[] args)
{
Client(args);
}
else if (args[0] == "timed")
{
Both(args);
}
else
{
Console.WriteLine("Usage:");
Console.WriteLine(" LoadTest");
Console.WriteLine(" LoadTest server <port>");
Console.WriteLine(" LoadTest client <host> <port> <clients>");
Console.WriteLine(" LoadTest timed <port> <seconds>");
}
}

public static void Both()
public static void Both(string[] args)
{
int port = 1337;
int seconds = 0;

if(args.Length == 3)
{
port = int.Parse(args[1]);
seconds = int.Parse(args[2]);
}

Thread serverThread = new Thread(() =>
{
RunServer.StartServer(1337);
RunServer.StartServer(port, seconds);
});
serverThread.IsBackground = false;
serverThread.Start();

// test 500 clients, which means 500+500 = 1000 connections total.
// this should be enough for any server or MMO.
RunClients.StartClients("127.0.0.1", 1337, 500);

RunClients.StartClients("127.0.0.1", port, 500, seconds);
}

public static void Server(string [] args)
Expand All @@ -55,7 +67,7 @@ public static void Server(string [] args)
}
int port = int.Parse(args[1]);

RunServer.StartServer(port);
RunServer.StartServer(port, 0);

}

Expand All @@ -71,7 +83,7 @@ public static void Client(string[] args)
int port = int.Parse(args[2]);
int clients = int.Parse(args[3]);

RunClients.StartClients(ip, port, clients);
RunClients.StartClients(ip, port, clients, 0);
}
}
}
12 changes: 10 additions & 2 deletions LoadTest/RunClients.cs
Expand Up @@ -14,7 +14,7 @@ public class RunClients
static long messagesReceived = 0;
static long dataReceived = 0;

public static void StartClients(string host, int port, int clientAmount)
public static void StartClients(string host, int port, int clientAmount, int seconds)
{
Log.Error("starting " + clientAmount + " clients...");

Expand Down Expand Up @@ -93,7 +93,15 @@ public static void StartClients(string host, int port, int clientAmount)
timer.AutoReset = true;
timer.Enabled = true;

Console.ReadLine();
if(seconds == 0)
{
Console.ReadLine();
}
else
{
Thread.Sleep(seconds * 1000);
}

timer.Stop();
timer.Dispose();

Expand Down
12 changes: 10 additions & 2 deletions LoadTest/RunServer.cs
Expand Up @@ -9,7 +9,7 @@ public class RunServer
static long messagesReceived = 0;
static long dataReceived = 0;

public static void StartServer(int port)
public static void StartServer(int port, int seconds)
{

// create server
Expand All @@ -28,7 +28,10 @@ public static void StartServer(int port)

Stopwatch stopwatch = Stopwatch.StartNew();

while (true)
var runTimer = Stopwatch.StartNew();
bool runServer = true;

while (runServer)
{
// tick and process as many as we can. will auto reply.
// (100k limit to avoid deadlocks)
Expand All @@ -46,6 +49,11 @@ public static void StartServer(int port)
messagesReceived = 0;
dataReceived = 0;
}

if (seconds != 0)
{
runServer = (runTimer.ElapsedMilliseconds < (seconds * 1000));
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -2,6 +2,8 @@

[![Discord](https://img.shields.io/discord/343440455738064897.svg)](https://discordapp.com/invite/N9QVxbM)

[![CI](https://github.com/vis2k/Telepathy/actions/workflows/main.yml/badge.svg)](https://github.com/vis2k/Telepathy/actions/workflows/main.yml)

Simple, message based, allocation free MMO Scale TCP networking in C#. And no magic.

Telepathy was designed with the [KISS Principle](https://en.wikipedia.org/wiki/KISS_principle) in mind.<br/>
Expand Down
1 change: 1 addition & 0 deletions Telepathy.Tests/Telepathy.Tests.csproj
Expand Up @@ -8,6 +8,7 @@


<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="OpenCover" Version="4.7.906-rc" />
Expand Down

0 comments on commit 0a06fe7

Please sign in to comment.