/// <summary> /// The arguments to start the coordinator must begin with: /// /// "simulated_player_spawn_count={integer}", /// "coordinator_spawn_interval_millis={integer}", /// "coordinator_start_delay_millis={integer}", /// "<IMPROBABLE_WORKER_ID>" /// /// All following arguments are passed to the simulated player process, where /// the "<IMPROBABLE_WORKER_ID>" placeholder will be replaced by the /// worker id of the simulated player. /// </summary> public static RegisseurWorkerCoordinator FromArgs(Logger logger, string[] args) { var numArgsToSkip = 3; LifetimeComponent lifetimeComponent = LifetimeComponent.Create(logger, args, out int numArgs); numArgsToSkip += numArgs; RegisseurWorkerCoordinator coordinator = new RegisseurWorkerCoordinator(logger) { NumSimulatedPlayersToStart = Util.GetIntegerArgumentOrDefault(args, SimulatedPlayerSpawnCountArg, 1), InitialStartDelayMillis = Util.GetIntegerArgumentOrDefault(args, InitialStartDelayArg, 10000), StartIntervalMillis = Util.GetIntegerArgumentOrDefault(args, SpawnIntervalArg, 1000), LifetimeComponent = lifetimeComponent, // First 3 arguments are for the coordinator worker only. // The 4th argument (worker id) is consumed by the simulated player startup script, // and not passed to the simulated player. SimulatedPlayerArgs = args.Skip(numArgsToSkip).ToArray() }; coordinator.LifetimeComponent.SetHost(coordinator); return(coordinator); }
public static void Run() { // Set test arguments // Set `maxLifetime=0` means use non-lifetime mode. var testArgs = new[] { $"{LifetimeComponent.MaxLifetimeArg}=0", $"{LifetimeComponent.MinLifetimeArg}=1", $"{LifetimeComponent.RestartAfterSecondsArg}=10", $"{LifetimeComponent.UseNewSimulatedPlayerArg}=0" }; var logger = new LoggerTest(); var component = LifetimeComponent.Create(logger, testArgs, out var num); component.SetHost(new LifetimeComponentHostTest()); for (var i = 0; i < 10; ++i) { component.AddSimulatedPlayer(new ClientInfo() { ClientName = $"simplayer-{Guid.NewGuid()}", StartTime = DateTime.Now.AddSeconds(2 + 2 * i) }); } component.Start(); logger.WriteLog("Finish test."); }
/// <summary> /// The arguments to start the coordinator must begin with: /// receptionist /// {hostname} Receptionist hostname /// {port} Receptionist port /// {worker_id} Worker id of the coordinator /// /// Next, two optional arguments can be specified: /// simulated_player_spawn_count={value} Number of simulated player clients to start per coordinator (defaults to 1) /// coordinator_start_delay_millis={value} Minimum delay before the coordinator starts a simulated client, to prevent clients /// from connecting too soon to the target deployment (defaults to 10000) /// /// All following arguments will be passed to the simulated player instance. /// These arguments can contain the following placeholders, which will be replaced by the coordinator: /// `<IMPROBABLE_SIM_PLAYER_WORKER_ID>` will be replaced with the worker id of the simulated player /// `<DEV_AUTH_TOKEN>` if a development auth token is specified as a worker flag, this will be replaced by the generated development auth login token /// `<TARGET_DEPLOYMENT>` will be replaced with the name of the deployment the simulated player clients will connect to /// /// WORKER FLAGS /// Additionally, the following worker flags are expected by the coordinator: /// simulated_players_dev_auth_token The development auth token used to generate login tokens and player identity tokens /// simulated_players_target_deployment Name of the target deployment which the simulated players will connect to /// target_num_simulated_players The total number of simulated players that will connect to the target deployment. This value is used to determine the delay in connecting simulated players. /// </summary> public static ManagedWorkerCoordinator FromArgs(Logger logger, string[] args) { // Keeps track of the number of arguments used for the coordinator. // The first 4 arguments are for connecting to the Receptionist. // 2 optional arguments can be provided after the Receptionist args to // modify the default options of the coordinator. var numArgsToSkip = 4; // Optional args with default values. var numSimulatedPlayersToStart = 1; var initialStartDelayMillis = 10000; if (Util.HasIntegerArgument(args, SimulatedPlayerSpawnCountArg)) { numSimulatedPlayersToStart = Util.GetIntegerArgument(args, SimulatedPlayerSpawnCountArg); numArgsToSkip++; } if (Util.HasIntegerArgument(args, InitialStartDelayArg)) { initialStartDelayMillis = Util.GetIntegerArgument(args, InitialStartDelayArg); numArgsToSkip++; } LifetimeComponent lifetimeComponent = LifetimeComponent.Create(logger, args, out int numArgs); numArgsToSkip += numArgs; ManagedWorkerCoordinator coordinator = new ManagedWorkerCoordinator(logger) { // Receptionist args. ReceptionistHost = args[1], ReceptionistPort = Convert.ToUInt16(args[2]), CoordinatorWorkerId = args[3], // Coordinator options. NumSimulatedPlayersToStart = numSimulatedPlayersToStart, InitialStartDelayMillis = initialStartDelayMillis, // Remove arguments that are only for the coordinator. SimulatedPlayerArgs = args.Skip(numArgsToSkip).ToArray(), // Lifetime component is an option. LifetimeComponent = lifetimeComponent }; coordinator.LifetimeComponent.SetHost(coordinator); return(coordinator); }