Skip to content

Commit

Permalink
Swap ClientEngineTests to use TempDir
Browse files Browse the repository at this point in the history
And also use the correct primitives to wait for state changes. This way
the tests won't deadlock forever in the event of a bug.
  • Loading branch information
alanmcgovern committed Aug 17, 2024
1 parent c871937 commit 6634e7d
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

using MonoTorrent.Connections;
using MonoTorrent.Connections.Peer;
using MonoTorrent.PieceWriter;

using NUnit.Framework;

Expand Down Expand Up @@ -501,23 +502,21 @@ public async Task SaveRestoreState_OneTorrentFile_NoContainingDirectory ()
public async Task StartAsyncAlwaysCreatesEmptyFiles ()
{
var files = TorrentFile.Create (Constants.BlockSize * 4, 0, 1, 2, 3);
using var writer = new TestWriter ();
using var rig = TestRig.CreateMultiFile (files, Constants.BlockSize * 4, writer);
using var accessor = TempDir.Create ();
using var rig = TestRig.CreateMultiFile (files, Constants.BlockSize * 4, new DiskWriter (), baseDirectory: accessor.Path);

for (int i = 0; i < 2; i++) {
var downloadingState = rig.Manager.WaitForState (TorrentState.Downloading);
var stoppedState = rig.Manager.WaitForState (TorrentState.Stopped);

await rig.Manager.StartAsync ();
Assert.IsTrue (downloadingState.Wait (5000), "Started");
Assert.DoesNotThrowAsync (() => rig.Manager.WaitForState (TorrentState.Downloading), "Started");
Assert.IsTrue (File.Exists (rig.Manager.Files[0].FullPath));
Assert.IsTrue (rig.Manager.Files[0].BitField.AllTrue);

// Files can be moved after they have been created.
await rig.Manager.MoveFileAsync (rig.Manager.Files[0], rig.Manager.Files[0].FullPath + "new_path");

await rig.Manager.StopAsync ();
Assert.IsTrue (stoppedState.Wait (5000), "Stopped");
Assert.DoesNotThrowAsync (() => rig.Manager.WaitForState (TorrentState.Stopped), "Stopped");
File.Delete (rig.Manager.Files[0].FullPath);
}
}
Expand Down

0 comments on commit 6634e7d

Please sign in to comment.