private DdpSubHandler SubscribeSync(string name, params object[] param) { DdpSubHandler handler = this._Subscribe(name, param); handler.SubSync(); return(handler); }
public DdpSubHandler Subscribe(string name, params object[] param) { DdpSubHandler handler = this._Subscribe(name, param); handler.Sub(); return(handler); }
private DdpSubHandler _Subscribe(string name, params object[] param) { DdpSubHandler handler = this.Connection.GetSubHandler(name, param); handler.NoSub += this.OnNoSub; this.Subscriptions.Add(handler); return(handler); }
public DdpSubHandler SubscribeTestUsers(int count) { this.Connection.CallSync("client.reserveTestUsers"); DdpSubHandler handler = this.SubscribeSync("client.testUsers"); int current; while ((current = this.Collections.TestUsers.Count) < count) { TestManager.Instance.State.Set("Waiting for test users " + current + "/" + count + "..."); Thread.Sleep(600); this.Connection.CallSync("client.reserveTestUsers"); } return(handler); }
private void Run() { DdpSubHandler testUsersSub = null; try { this.State.Set("Waiting for subscriptions..."); while (this.Thread.IsAlive && !ServerManager.Instance.AllSubscriptionsReady) { Thread.Sleep(100); } ConfigDoc config = ServerManager.Instance.Collections.Config.Values.FirstOrDefault(); if (config == null) { Logs.Error("[Test] Unable to get configuration"); this.Stop(); } int threadsPerClient = config.threadsPerClient.GetValueOrDefault(); bool sendTestUsers = config.sendTestUsers.GetValueOrDefault(); if (sendTestUsers) { testUsersSub = ServerManager.Instance.SubscribeTestUsers(threadsPerClient); this.Users = new Queue <TestUserDoc>(ServerManager.Instance.Collections.TestUsers.Values.Take(threadsPerClient)); } this.StateUpdate.Start(); this.State.Set("Running", State.EType.SUCCESS); while (this.Thread.IsAlive) { for (int i = this.Stories.Count; this.Thread.IsAlive && i < threadsPerClient; i++) { StoryBase story = ServerManager.Instance.CreateStory(); if (story == null) { Logs.Error("[Test] Script not exists"); this.Stop(); } TestUserDoc user = null; if (sendTestUsers) { if (this.Users.Count == 0) { Logs.Error("[Test] User account is missing"); this.Stop(); } user = this.Users.Dequeue(); } story.End += OnEnd; this.Stories.Add(story); story.Start(config.server.host, config.server.ssl, user); this.OnStoriesChangeInvoke(); if (config.delay.to.HasValue) { Thread.Sleep(this.RND.Next(config.delay.from, config.delay.to.Value)); } else { Thread.Sleep(config.delay.from); } } Thread.Sleep(1000); } } catch (ThreadAbortException) { } finally { this.StateUpdate.Stop(); StoryBase[] temp = this.Stories.ToArray(); foreach (StoryBase story in temp) { if (story != null) { story.Stop(); } } this.Stories.Clear(); this.ExecutedStoriesCount = 0; if (this.Users != null) { this.Users.Clear(); this.Users = null; } if (ServerManager.Instance.IsConnected && testUsersSub != null) { testUsersSub.Unsub(); } this.OnStoriesChangeInvoke(false); this.StateUpdate.UpdateStories(); this.State.Set("Idle", State.EType.FAILED); } }