Skip to content

Commit

Permalink
- Fix for DownloadMode.UpdateSeedingDownloadingState logic. Currently…
Browse files Browse the repository at this point in the history
… it sends multiple TorrentStateChanged events during download
  • Loading branch information
vlasenkoalexey authored and alanmcgovern committed Apr 13, 2020
1 parent 57f7c22 commit c407ba0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,39 @@ public void PartialProgress_RelatedDownloaded2 ()
Assert.AreEqual (TorrentState.Downloading, Manager.State, "#2");
}

[Test]
public void PartialProgress_RelatedDownloaded_FileAdded ()
{
Manager.OnPieceHashed (0, true);

foreach (var file in Manager.Torrent.Files)
file.Priority = Priority.DoNotDownload;
Manager.Torrent.Files.First ().Priority = Priority.Normal;

var mode = new DownloadMode (Manager, DiskManager, ConnectionManager, Settings);
Manager.Mode = mode;
mode.UpdateSeedingDownloadingState ();
Assert.AreEqual (TorrentState.Seeding, Manager.State, "#1");

Manager.Torrent.Files.Skip (1).First ().Priority = Priority.Normal;
TorrentState oldState = TorrentState.Error;
TorrentState newState = TorrentState.Error;
Manager.TorrentStateChanged += (object sender, TorrentStateChangedEventArgs e) => {
oldState = e.OldState;
newState = e.NewState;
};
mode.UpdateSeedingDownloadingState ();

Assert.That (Manager.Progress, Is.GreaterThan (0.0), "#3a");
Assert.That (Manager.Progress, Is.LessThan (100.0), "#3b");

Assert.That (Manager.PartialProgress, Is.LessThan (100.0), "#4");
Assert.AreEqual (TorrentState.Downloading, Manager.State, "#5");

Assert.AreEqual (TorrentState.Seeding, oldState, "#6");
Assert.AreEqual (TorrentState.Downloading, newState, "#7");
}

[Test]
public void PartialProgress_UnrelatedDownloaded_AllDoNotDownload ()
{
Expand Down
4 changes: 2 additions & 2 deletions src/MonoTorrent/MonoTorrent.Client/Modes/DownloadMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ internal void UpdateSeedingDownloadingState ()
state = TorrentState.Seeding;
Manager.RaiseTorrentStateChanged (new TorrentStateChangedEventArgs (Manager, TorrentState.Downloading, TorrentState.Seeding));
} else if (Manager.Bitfield.CountTrue (Manager.PartialProgressSelector) < Manager.PartialProgressSelector.TrueCount && state == TorrentState.Seeding) {
state = TorrentState.Seeding;
Manager.RaiseTorrentStateChanged (new TorrentStateChangedEventArgs (Manager, TorrentState.Downloading, TorrentState.Seeding));
state = TorrentState.Downloading;
Manager.RaiseTorrentStateChanged (new TorrentStateChangedEventArgs (Manager, TorrentState.Seeding, TorrentState.Downloading));
}
}
}
Expand Down

0 comments on commit c407ba0

Please sign in to comment.