Skip to content

Commit

Permalink
Merge pull request #54 from LSViana/34-investigate-possible-memory-le…
Browse files Browse the repository at this point in the history
…aks-part-1

Investigate possible memory leaks (part 1)
  • Loading branch information
LSViana authored Oct 19, 2023
2 parents d1a298f + a4f5798 commit a3053da
Show file tree
Hide file tree
Showing 56 changed files with 1,741 additions and 88 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- 'main'
- '34-investigate-possible-memory-leaks'

jobs:
test:
Expand Down
6 changes: 6 additions & 0 deletions Tests/YDotNet.Tests.Driver/Abstractions/ITask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace YDotNet.Tests.Driver.Abstractions;

public interface ITask
{
Task Run();
}
5 changes: 5 additions & 0 deletions Tests/YDotNet.Tests.Driver/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// See https://aka.ms/new-console-template for more information

using YDotNet.Tests.Driver.Tasks.Docs;

new ObserveSubDocs().Run();
40 changes: 40 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/Create.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using YDotNet.Document;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class Create : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
doc.Array($"sample-{i}");
doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
52 changes: 52 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/Get.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class Get : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var array = doc.Array($"sample-{i}");

var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Long(value: 2469L),
Input.Boolean(value: false)
});
array.Get(transaction, index: 1);
transaction.Commit();

doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
46 changes: 46 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/InsertRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class InsertRange : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var array = doc.Array($"sample-{i}");

var transaction = doc.WriteTransaction();
array.InsertRange(transaction, index: 0, new[] { Input.Long(value: 2469L) });
transaction.Commit();

doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
53 changes: 53 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/Iterate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class Iterate : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var array = doc.Array($"sample-{i}");

var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Long(value: 2469L),
Input.Boolean(value: false),
Input.Undefined()
});
array.Iterate(transaction).ToArray();
transaction.Commit();

doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
47 changes: 47 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/Length.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class Length : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var array = doc.Array($"sample-{i}");

var transaction = doc.WriteTransaction();
array.InsertRange(transaction, index: 0, new[] { Input.Long(value: 2469L) });
var _ = array.Length;
transaction.Commit();

doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
53 changes: 53 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/Move.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class Move : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var array = doc.Array($"sample-{i}");

var transaction = doc.WriteTransaction();
array.InsertRange(
transaction, index: 0, new[]
{
Input.Long(value: 2469L),
Input.Boolean(value: false),
Input.Undefined()
});
array.Move(transaction, sourceIndex: 0, targetIndex: 2);
transaction.Commit();

doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
49 changes: 49 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Arrays/Observe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using YDotNet.Document;
using YDotNet.Document.Cells;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Arrays;

public class Observe : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tArrays:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var array = doc.Array($"sample-{i}");

var subscription = array.Observe(_ => { });

var transaction = doc.WriteTransaction();
array.InsertRange(transaction, index: 0, new[] { Input.Long(value: 2469L) });
transaction.Commit();

array.Unobserve(subscription);
doc.Dispose();
count++;
}
}

return Task.CompletedTask;
}
}
Loading

0 comments on commit a3053da

Please sign in to comment.