Beispiel #1
0
        public void MultipleRequests_Sequential(int repeatCount)
        {
            // Verify that the server is able to handle multiple requests
            // submitted one at a time.

            var client = new ProfileClient(pipeName);

            using (var server = new ProfileServer(pipeName))
            {
                SetDefaultHandlers(server);
                server.Start();

                Assert.Equal("zero-profile", client.GetProfileValue("zero"));
                Assert.Equal("one-profile", client.GetProfileValue("one"));
                Assert.Equal("two-profile", client.GetProfileValue("two"));
                Assert.Equal("three-profile", client.GetProfileValue("three"));
                Assert.Equal("four-profile", client.GetProfileValue("four"));
                Assert.Equal("five-profile", client.GetProfileValue("five"));
                Assert.Equal("six-profile", client.GetProfileValue("six"));
                Assert.Equal("seven-profile", client.GetProfileValue("seven"));
                Assert.Equal("eight-profile", client.GetProfileValue("eight"));
                Assert.Equal("nine-profile", client.GetProfileValue("nine"));

                var callArgs = new Dictionary <string, string>();

                callArgs["command"] = "Hello World!";

                Assert.Equal("Hello World!", client.Call(callArgs));
            }
        }
Beispiel #2
0
        /// <summary>
        /// <para>
        /// <b>INTERNAL USE ONLY:</b> Deploys a new cluster using the current user's <b>neon-assistant</b>
        /// <b>clusterdefinition.key</b> profile value to determine which of the built-in cluster definitions
        /// from <see cref="KubeTestHelper.ClusterDefinitions"/> to be used for unit testing in the user's
        /// environment.
        /// </para>
        /// <note>
        /// This method removes any existing neonKUBE cluster before deploying a fresh one.
        /// </note>
        /// </summary>
        /// <param name="options">
        /// Optionally specifies the options that <see cref="ClusterFixture"/> will use to
        /// manage the test cluster.
        /// </param>
        /// <returns>
        /// <para>
        /// The <see cref="TestFixtureStatus"/>:
        /// </para>
        /// <list type="table">
        /// <item>
        ///     <term><see cref="TestFixtureStatus.Disabled"/></term>
        ///     <description>
        ///     Returned when cluster unit testing is disabled due to the <c>NEON_CLUSTER_TESTING</c> environment
        ///     variable not being present on the current machine which means that <see cref="TestHelper.IsClusterTestingEnabled"/>
        ///     returns <c>false</c>.
        ///     </description>
        /// </item>
        /// <item>
        ///     <term><see cref="TestFixtureStatus.Started"/></term>
        ///     <description>
        ///     Returned when one of the <c>Start()</c> methods is called for the first time for the fixture
        ///     instance, indicating that an existing cluster has been connected or a new cluster has been deployed.
        ///     </description>
        /// </item>
        /// <item>
        ///     <term><see cref="TestFixtureStatus.AlreadyRunning"/></term>
        ///     <description>
        ///     Returned when one of the <c>Start()</c> methods has already been called by your test
        ///     class instance.
        ///     </description>
        /// </item>
        /// </list>
        /// </returns>
        /// <remarks>
        /// <para>
        /// <b>IMPORTANT:</b> Only one <see cref="ClusterFixture"/> can be run at a time on
        /// any one computer.  This is due to the fact that cluster state like the kubeconfig,
        /// neonKUBE logins, logs and other files will be written to <b>~/.neonkube/spaces/$fixture/*</b>
        /// so multiple fixture instances will be confused when trying to manage these same files.
        /// </para>
        /// <para>
        /// This means that not only will running <see cref="ClusterFixture"/> based tests in parallel
        /// within the same instance of Visual Studio fail, but but running these tests in different
        /// Visual Studio instances will also fail.
        /// </para>
        /// </remarks>
        /// <exception cref="KeyNotFoundException">
        /// Thrown when the cluster definition requested by the <b>clusterdefinition.key</b>
        /// does not exist.
        /// </exception>
        /// <exception cref="ProfileException">
        /// Thrown when the <b>clusterdefinition.key</b> profile value could not be retrieved.
        /// </exception>
        public TestFixtureStatus StartWithNeonAssistant(ClusterFixtureOptions options = null)
        {
            var profileClient = new ProfileClient();
            var key           = profileClient.GetProfileValue("clusterdefinition.key");

            return(StartWithClusterDefinition(ClusterDefinition.FromYaml(KubeTestHelper.ClusterDefinitions[key], strict: true, validate: true), options));
        }
Beispiel #3
0
        public void GetProfileValue(int repeatCount)
        {
            var client = new ProfileClient(pipeName);

            using (var server = new ProfileServer(pipeName))
            {
                SetDefaultHandlers(server);
                server.Start();

                Assert.Equal("test-profile", client.GetProfileValue("test"));
            }
        }
Beispiel #4
0
        public void GetProfileValue_Exception(int repeatCount)
        {
            var client = new ProfileClient(pipeName);

            using (var server = new ProfileServer(pipeName))
            {
                SetDefaultHandlers(server);

                server.GetProfileValueHandler = (request, name) => throw new Exception("test exception");

                server.Start();

                Assert.Throws <ProfileException>(() => client.GetProfileValue("test"));
            }
        }
Beispiel #5
0
        public async Task MultipleRequests_Parallel(int repeatCount)
        {
            // Verify that the server is able to handle multiple requests
            // submitted in parallel but with only one server thread.

            var client = new ProfileClient(pipeName);

            using (var server = new ProfileServer(pipeName, threadCount: 1))
            {
                SetDefaultHandlers(server);
                server.Start();

                await Task.Run(() => Assert.Equal("zero-profile", client.GetProfileValue("zero")));

                await Task.Run(() => Assert.Equal("one-profile", client.GetProfileValue("one")));

                await Task.Run(() => Assert.Equal("two-profile", client.GetProfileValue("two")));

                await Task.Run(() => Assert.Equal("three-profile", client.GetProfileValue("three")));

                await Task.Run(() => Assert.Equal("four-profile", client.GetProfileValue("four")));

                await Task.Run(() => Assert.Equal("five-profile", client.GetProfileValue("five")));

                await Task.Run(() => Assert.Equal("six-profile", client.GetProfileValue("six")));

                await Task.Run(() => Assert.Equal("seven-profile", client.GetProfileValue("seven")));

                await Task.Run(() => Assert.Equal("eight-profile", client.GetProfileValue("eight")));

                await Task.Run(() => Assert.Equal("nine-profile", client.GetProfileValue("nine")));
            }

            // Verify that the server is able to handle multiple requests
            // submitted in parallel with multiple server threads.

            using (var server = new ProfileServer(pipeName, threadCount: 10))
            {
                SetDefaultHandlers(server);
                server.Start();

                await Task.Run(() => Assert.Equal("zero-profile", client.GetProfileValue("zero")));

                await Task.Run(() => Assert.Equal("one-profile", client.GetProfileValue("one")));

                await Task.Run(() => Assert.Equal("two-profile", client.GetProfileValue("two")));

                await Task.Run(() => Assert.Equal("three-profile", client.GetProfileValue("three")));

                await Task.Run(() => Assert.Equal("four-profile", client.GetProfileValue("four")));

                await Task.Run(() => Assert.Equal("five-profile", client.GetProfileValue("five")));

                await Task.Run(() => Assert.Equal("six-profile", client.GetProfileValue("six")));

                await Task.Run(() => Assert.Equal("seven-profile", client.GetProfileValue("seven")));

                await Task.Run(() => Assert.Equal("eight-profile", client.GetProfileValue("eight")));

                await Task.Run(() => Assert.Equal("nine-profile", client.GetProfileValue("nine")));
            }
        }