public void testFiveSecondSingleton() { FiveSecondSingleton s1 = FiveSecondSingleton.Instance(); FiveSecondSingleton s2 = FiveSecondSingleton.Instance(); Assert.IsNotNull(s1); Assert.IsNotNull(s2); Assert.AreSame(s1, s2); }
public void TestFiveSecondSingleton_wait() { FiveSecondSingleton s1, s2; s1 = FiveSecondSingleton.Instance(); Thread.Sleep(TimeSpan.FromSeconds(6)); s2 = FiveSecondSingleton.Instance(); Assert.IsNotNull(s1); Assert.IsNotNull(s2); Assert.AreNotSame(s1, s2); }
public void TestSingleton3() { FiveSecondSingleton s1, s2, s3; s1 = FiveSecondSingleton.GetInstance(); Thread.Sleep(TimeSpan.FromSeconds(4)); s2 = FiveSecondSingleton.GetInstance(); Thread.Sleep(TimeSpan.FromSeconds(2)); s3 = FiveSecondSingleton.GetInstance(); Assert.AreSame(s1, s2); Assert.AreNotSame(s1, s3); Assert.AreNotSame(s2, s3); }
public void testFiveSecondSingleton_threads() { Thread t1, t2; FiveSecondSingleton s1 = null, s2 = null; t1 = new Thread(() => { s1 = FiveSecondSingleton.Instance(); }); t2 = new Thread(() => { s2 = FiveSecondSingleton.Instance(); }); t1.Start(); t2.Start(); t2.Join(); t1.Join(); Assert.IsNotNull(s1); Assert.IsNotNull(s2); Assert.AreSame(s1, s2); }