Example #1
0
        public virtual void InitTests()
        {
            m_currentTestClass = this.GetType();

            if (m_timings == null)
            {
                object[] attrs;
                // Get the list of tests for this class and fixture setup method.
                foreach (MethodInfo method in m_currentTestClass.GetMethods())
                {
                    if (m_fixtureSetup == null)
                    {
                        attrs = method.GetCustomAttributes(
                            typeof(TestFixtureSetUpAttribute), true);
                        if (attrs != null && attrs.Length > 0)
                        {
                            m_fixtureSetup = method;
                        }
                    }
                    attrs = method.GetCustomAttributes(
                        typeof(TestAttribute), true);
                    if (attrs != null && attrs.Length > 0)
                    {
                        m_tests.Add(method);
                    }
                }
                m_timeBomb.SetFixtureSetup(m_fixtureSetup, this);
                // Get the default timeout
                string timingsFile = TimeoutsXML;
                m_timings = XmlNodeReaderWriter.GetInstance(timingsFile);
                try
                {
                    string timeoutStr = m_timings.GetAttribute(
                        '/' + XmlNodeReaderWriter.RootNodeName, TimeoutAttribName);
                    if (timeoutStr != null)
                    {
                        m_defaultTimeoutMillis = int.Parse(timeoutStr) * 1000;
                    }
                }
                catch (Exception ex)
                {
                    Util.Log("Got an exception while setting default timeout from {0}: {1}",
                             timingsFile, ex);
                    m_defaultTimeoutMillis = -1;
                }
                NUnitMethodComparer mComp = new NUnitMethodComparer();
                m_tests.Sort(mComp);
            }
            SetLogging(GetClassLogFile());
            m_clients = GetClients();
            m_timeBomb.AddClients(m_clients);
            SetClientLogging();
        }
Example #2
0
 /// <summary>
 /// Remove an instance from the global table.
 /// </summary>
 /// <param name="path">The path of the XML file whose instance is to be removed.</param>
 public static void RemoveInstance(string path)
 {
     if (path != null)
     {
         lock (((ICollection)instances).SyncRoot)
         {
             if (instances.ContainsKey(path))
             {
                 XmlNodeReaderWriter instance = instances[path];
                 instance.Close();
                 instances.Remove(path);
             }
         }
     }
 }
Example #3
0
        public virtual void InitTest()
        {
            if (m_currentTestNumber < m_tests.Count)
            {
                m_currentTest = m_tests[m_currentTestNumber];
                m_currentTestNumber++;

                SetLogging(GetLogFile());
                SetClientLogging();
                int timeout = m_defaultTimeoutMillis;
                if (m_defaultTimeoutMillis > 0)
                {
                    string timingsFile = TimeoutsXML;
                    try
                    {
                        // Find the timeout set for this test in the Settings file.
                        string timeoutStr = m_timings.GetAttribute(
                            XmlNodeReaderWriter.GetPathForNode(m_currentTest),
                            TimeoutAttribName);
                        if (timeoutStr != null)
                        {
                            timeout = int.Parse(timeoutStr) * 1000;
                        }
                    }
                    catch (Exception ex)
                    {
                        Util.Log("Got an exception while setting timeout from {0}: {1}",
                                 timingsFile, ex);
                        timeout = m_defaultTimeoutMillis;
                    }
                }
                else
                {
                    timeout = Timeout.Infinite;
                }
                DateTime now = DateTime.Now;
                Console.WriteLine("[{0}:{1}:{2}.{3}] Set the timeout to {4} secs.{5}",
                                  now.Hour.ToString("D02"), now.Minute.ToString("D02"),
                                  now.Second.ToString("D02"), now.Millisecond.ToString("D03"),
                                  timeout / 1000, Environment.NewLine);
                Util.Log("INIT:: Starting next test in {0} with timeout as {1} secs.",
                         this.GetType().FullName, timeout / 1000);
                m_timeBomb.TaskName = GetTaskName();
                m_timeBomb.Start(timeout);
            }
        }
Example #4
0
        /// <summary>
        /// Get an instance of ReadConfig for the given configuration file.
        /// </summary>
        /// <param name="path">The path of the XML file to read.</param>
        /// <returns>An instance of ReadConfig object to be able to read key/value pairs.</returns>
        public static XmlNodeReaderWriter GetInstance(string path)
        {
            XmlNodeReaderWriter instance = null;

            if (path != null)
            {
                lock (((ICollection)instances).SyncRoot)
                {
                    if (instances.ContainsKey(path))
                    {
                        instance = instances[path];
                    }
                    else
                    {
                        instance = new XmlNodeReaderWriter(path);
                        instances.Add(path, instance);
                    }
                }
            }
            return(instance);
        }