Skip to content

Instantly share code, notes, and snippets.

@biac
Created December 6, 2011 09:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save biac/1437473 to your computer and use it in GitHub Desktop.
FeedReader: 並列実行のテスト
private readonly string[] RssUrls = {
// Amazon.co.jp: 本 > コンピュータ・IT > プログラミングのベストセラー
"http://www.amazon.co.jp/gp/rss/bestsellers/books/492352/ref=zg_bs_492352_rsslink",
// Amazon.co.jp: パソコン・周辺機器 > ノートパソコンで一番ギフトとして贈られている商品
"http://www.amazon.co.jp/gp/rss/most-gifted/computers/2151981051/ref=zg_mg_2151981051_rsslink",
// Amazon.co.jp: ソフトウェアで一番ほしい物リストに追加されている商品
"http://www.amazon.co.jp/gp/rss/most-wished-for/software/ref=zg_mw_software_rsslink",
// Amazon.co.jp: DVD > アニメの新着ニューリリース
"http://www.amazon.co.jp/gp/rss/new-releases/dvd/562020/ref=zg_bsnr_562020_rsslink",
// Amazon.co.jp: MP3ダウンロード > MP3 楽曲のヒット商品
"http://www.amazon.co.jp/gp/rss/movers-and-shakers/dmusic/digital-music-track/ref=zg_bsms_digital-music-track_rsslink",
};
[TestMethod]
public void ReadAsync2Test1()
{
Stopwatch sw = Stopwatch.StartNew();
Task<IList<FeedData>> task = (new FeedReader()).ReadAsync(RssUrls);
sw.Stop();
Assert.IsFalse(task.IsCompleted, "ReadAsync 呼び出し直後"); //非同期実行中
//Assert.AreEqual<long>(0, sw.ElapsedMilliseconds);
Assert.IsTrue(200L > sw.ElapsedMilliseconds); //実際には 50mSec 程度
sw.Restart();
IList<FeedData> fdList = task.GetAwaiter().GetResult();
sw.Stop();
StringAssert.StartsWith(fdList[0].Title, "Amazon.co.jp: 本");
StringAssert.StartsWith(fdList[1].Title, "Amazon.co.jp: パソコン");
StringAssert.StartsWith(fdList[2].Title, "Amazon.co.jp: ソフトウェア");
StringAssert.StartsWith(fdList[3].Title, "Amazon.co.jp: DVD");
StringAssert.StartsWith(fdList[4].Title, "Amazon.co.jp: MP3");
//Assert.AreEqual<long>(0, sw.ElapsedMilliseconds);
Assert.IsTrue(3000L > sw.ElapsedMilliseconds); //5倍よりは短時間(2CPUなら半分程度)で終わってほしい
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment