Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/17 09:45:36 (7 years ago)
Author:
jkarder
Message:

#2258: refactored async methods

  • synchronously called IExecutables are now executed in the caller's thread
  • removed old synchronization code from unit tests
Location:
branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GaussianProcessRegressionTest.cs

    r12012 r15065  
    2222using System;
    2323using System.Linq;
    24 using System.Threading;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Problems.DataAnalysis;
     
    3938    }
    4039
    41     private EventWaitHandle trigger = new AutoResetEvent(false);
    4240    private Exception ex;
    4341
     
    6563
    6664      alg.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
    67       alg.Stopped += new EventHandler(cv_Stopped);
    6865
    6966      alg.Prepare();
    7067      alg.Start();
    71       trigger.WaitOne();
    7268      if (ex != null) throw ex;
    7369
     
    7874      ex = e.Value;
    7975    }
    80 
    81     private void cv_Stopped(object sender, EventArgs e) {
    82       trigger.Set();
    83     }
    8476  }
    8577}
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/GradientBoostingTest.cs

    r13157 r15065  
    11using System;
    22using System.Linq;
    3 using System.Threading;
    43using HeuristicLab.Data;
    5 using HeuristicLab.Optimization;
    64using HeuristicLab.Problems.DataAnalysis;
    75using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    182180      #endregion
    183181
    184       RunAlgorithm(gbt);
     182      gbt.Start();
    185183
    186184      Console.WriteLine(gbt.ExecutionTime);
     
    210208      #endregion
    211209
    212       RunAlgorithm(gbt);
     210      gbt.Start();
    213211
    214212      Console.WriteLine(gbt.ExecutionTime);
     
    238236      #endregion
    239237
    240       RunAlgorithm(gbt);
     238      gbt.Start();
    241239
    242240      Console.WriteLine(gbt.ExecutionTime);
    243241      Assert.AreEqual(0.061954221604374943, ((DoubleValue)gbt.Results["Loss (train)"].Value).Value, 1E-6);
    244242      Assert.AreEqual(0.06316303473499961, ((DoubleValue)gbt.Results["Loss (test)"].Value).Value, 1E-6);
    245     }
    246 
    247     // same as in SamplesUtil
    248     private void RunAlgorithm(IAlgorithm a) {
    249       var trigger = new EventWaitHandle(false, EventResetMode.ManualReset);
    250       Exception ex = null;
    251       a.Stopped += (src, e) => { trigger.Set(); };
    252       a.ExceptionOccurred += (src, e) => { ex = e.Value; trigger.Set(); };
    253       a.Prepare();
    254       a.Start();
    255       trigger.WaitOne();
    256 
    257       Assert.AreEqual(ex, null);
    258243    }
    259244
  • branches/Async/HeuristicLab.Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/SupportVectorMachineTest.cs

    r12012 r15065  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Threading;
    2625using HeuristicLab.Algorithms.DataAnalysis;
    2726using HeuristicLab.Common;
     
    5049    }
    5150
    52     private EventWaitHandle trigger = new AutoResetEvent(false);
    5351    private Exception ex;
    5452
     
    7169
    7270      cv.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(cv_ExceptionOccurred);
    73       cv.Stopped += new EventHandler(cv_Stopped);
    7471
    7572      cv.Prepare();
    7673      cv.Start();
    77       trigger.WaitOne();
    7874      if (ex != null) throw ex;
    7975
     
    10298      ex = e.Value;
    10399    }
    104 
    105     private void cv_Stopped(object sender, EventArgs e) {
    106       trigger.Set();
    107     }
    108100  }
    109101}
Note: See TracChangeset for help on using the changeset viewer.