Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gui/Services/HealthMonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public void Start(Func<bool> shouldCheck, Func<(string Host, int Port)> endpoint
}

Checked?.Invoke(result);
await Task.Delay(TimeSpan.FromSeconds(10), ct);
await Task.Delay(TimeSpan.FromSeconds(60), ct);
}
catch (OperationCanceledException) { }
catch (Exception ex)
{
Checked?.Invoke(new HealthCheckResult(false, 0, DateTime.Now, ex.Message));
try { await Task.Delay(TimeSpan.FromSeconds(10), ct); }
try { await Task.Delay(TimeSpan.FromSeconds(60), ct); }
catch (OperationCanceledException) { }
}
}
Expand Down
21 changes: 21 additions & 0 deletions test_culture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
[JsonPropertyName("speed_down")] public double SpeedDown { get; set; }
}

public class Program {
public static void Main() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
var options = new JsonSerializerOptions { NumberHandling = JsonNumberHandling.AllowReadingFromString };
string json = "{\"speed_up\": 1.23, \"speed_down\": 4.56}";
var s = JsonSerializer.Deserialize<StatsSnapshot>(json, options);
Console.WriteLine($"up: {s.SpeedUp}, down: {s.SpeedDown}");
}
}
10 changes: 10 additions & 0 deletions test_culture.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_culture.cs" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions test_format.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

public class Program {
public static string Bytes(double n)
{
string[] u = { "B", "KB", "MB", "GB", "TB" };
int i = 0;
while (n >= 1024 && i < u.Length - 1) { n /= 1024; i++; }
return n < 10 && i > 0 ? $"{n:0.00} {u[i]}" : $"{n:0.#} {u[i]}";
}
public static string PerSec(double bps) => Bytes(bps) + "/s";

public static void Main() {
Console.WriteLine(PerSec(415.7));
}
}
6 changes: 6 additions & 0 deletions test_format.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions test_format2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

public class Program {
public static string Bytes(double n)
{
string[] u = { "B", "KB", "MB", "GB", "TB" };
int i = 0;
while (n >= 1024 && i < u.Length - 1) { n /= 1024; i++; }
return n < 10 && i > 0 ? $"{n:0.00} {u[i]}" : $"{n:0.#} {u[i]}";
}
public static string PerSec(double bps) => Bytes(bps) + "/s";

public static void Main() {
Console.WriteLine(PerSec(415.7));
}
}
6 changes: 6 additions & 0 deletions test_format2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
16 changes: 16 additions & 0 deletions test_format3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

public class TestFormat3 {
public static string Bytes(double n)
{
string[] u = { "B", "KB", "MB", "GB", "TB" };
int i = 0;
while (n >= 1024 && i < u.Length - 1) { n /= 1024; i++; }
return n < 10 && i > 0 ? $"{n:0.00} {u[i]}" : $"{n:0.#} {u[i]}";
}
public static string PerSec(double bps) => Bytes(bps) + "/s";

public static void Main() {
Console.WriteLine(PerSec(415.7));
}
}
9 changes: 9 additions & 0 deletions test_format3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_format3.cs" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions test_format4.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_format3.cs" />
</ItemGroup>
</Project>
10 changes: 10 additions & 0 deletions test_format5.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_json.cs" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions test_json.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
[JsonPropertyName("speed_down")] public double SpeedDown { get; set; }
}

public class Program {
public static void Main() {
string json = "{\"speed_up\": 1.23, \"speed_down\": 4.56}";
var s = JsonSerializer.Deserialize<StatsSnapshot>(json);
Console.WriteLine($"up: {s.SpeedUp}, down: {s.SpeedDown}");
}
}
6 changes: 6 additions & 0 deletions test_json.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
17 changes: 17 additions & 0 deletions test_json2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
[JsonPropertyName("speed_down")] public double SpeedDown { get; set; }
}

public class Program {
public static void Main() {
string json = "{\"speed_up\": 1.23, \"speed_down\": 4.56}";
var s = JsonSerializer.Deserialize<StatsSnapshot>(json);
Console.WriteLine($"up: {s.SpeedUp}, down: {s.SpeedDown}");
}
}
6 changes: 6 additions & 0 deletions test_json2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
20 changes: 20 additions & 0 deletions test_json_culture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
[JsonPropertyName("speed_down")] public double SpeedDown { get; set; }
}

public class Program {
public static void Main() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
string json = "{\"speed_up\": 1.23, \"speed_down\": 4.56}";
var s = JsonSerializer.Deserialize<StatsSnapshot>(json);
Console.WriteLine($"up: {s.SpeedUp}, down: {s.SpeedDown}");
}
}
10 changes: 10 additions & 0 deletions test_json_culture.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_json_culture.cs" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions test_json_deser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
}

public class Program {
public static void Main() {
var options = new JsonSerializerOptions { NumberHandling = JsonNumberHandling.AllowReadingFromString };
var s = JsonSerializer.Deserialize<StatsSnapshot>("{\"speed_up\": 12.3}", options);
Console.WriteLine(s.SpeedUp);
}
}
10 changes: 10 additions & 0 deletions test_json_deser.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_json_deser.cs" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions test_json_deser2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
}

public class Program {
public static void Main() {
var s = JsonSerializer.Deserialize<StatsSnapshot>("{\"speed_up\": 12.3}");
Console.WriteLine(s.SpeedUp);
}
}
10 changes: 10 additions & 0 deletions test_json_deser2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_json_deser2.cs" />
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions test_json_deser3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
}

public class Program {
public static void Main() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
var s = JsonSerializer.Deserialize<StatsSnapshot>("{\"speed_up\": 12.3}");
Console.WriteLine(s.SpeedUp);
}
}
10 changes: 10 additions & 0 deletions test_json_deser3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_json_deser3.cs" />
</ItemGroup>
</Project>
18 changes: 18 additions & 0 deletions test_json_deser4.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;

public class StatsSnapshot
{
[JsonPropertyName("speed_up")] public double SpeedUp { get; set; }
}

public class Program {
public static void Main() {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
var s = JsonSerializer.Deserialize<StatsSnapshot>("{\"speed_up\": 12.3}");
Console.WriteLine(s.SpeedUp);
}
}
10 changes: 10 additions & 0 deletions test_json_deser4.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="test_json_deser4.cs" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions test_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import asyncio
from unittest.mock import Mock

class DummyWriter:
def write(self, data):
pass

w = DummyWriter()
import sys
sys.path.append("/app/core")
sys.path.append("/app/src")
import gui_bridge
gui_bridge._wrap_writer_for_down(w)
w.write(b"hello")

import stats
print(stats.snapshot())
22 changes: 22 additions & 0 deletions test_speed_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
sys.path.append("/app/core")
sys.path.append("/app/src")
import gui_bridge
import asyncio

class DummyReader:
async def read(self, n=-1):
return b"hello"
async def readline(self):
return b"hello"
async def readexactly(self, n):
return b"hello"

r = DummyReader()
gui_bridge._wrap_reader_for_up(r)
async def main():
await r.read(5)
import stats
print(stats.snapshot())

asyncio.run(main())
15 changes: 15 additions & 0 deletions test_wrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
sys.path.append("/app/core")
sys.path.append("/app/src")

class MockWriter:
def write(self, data):
pass

w = MockWriter()
import gui_bridge
gui_bridge._wrap_writer_for_down(w)
w.write(b"hello")

import stats
print(stats.snapshot())
Loading