[Buildbot] #3443: build.complete always false in coffeescript

Buildbot trac trac at buildbot.net
Mon Feb 8 19:36:42 UTC 2016


#3443: build.complete always false in coffeescript
------------------------+-------------------
Reporter:  gtmacdonald  |      Owner:
    Type:  defect       |     Status:  new
Priority:  major        |  Milestone:  0.9.+
 Version:  master       |   Keywords:
------------------------+-------------------
 In the following code, the two log.debug statements (towards the end) in
 onChange are outputting two different values for build.complete. When the
 build instance is printed to console (see attached png) it is true for a
 cancelled build, but build.complete reports false.

 {{{
 class _buildStatus extends Controller
     constructor: ($scope, $attrs, dataService, $log, RESULTS, $interval)
 ->
         $scope.builder = $attrs.builder
         $scope.name = $attrs.name
         $scope.status = 'unknown'
         $scope.pvalue = 0

         builders = $attrs.builders.split(',')

         data = dataService.open().closeOnDestroy($scope)

         estimates = {}
         pending = {}
         lastBuildResult = null

         arePending = ->
             for builderId, startedTimes of pending
                 for startedTime in startedTimes
                     return true
             return false

         filterOutliers = (someArray) ->
             # Copy the values, rather than operating on references to
 existing values
             values = someArray.concat()
             # Then sort
             values.sort (a, b) ->
                 a - b

             ### Then find a generous IQR. This is generous because if
 (values.length / 4)
             # is not an int, then really you should average the two
 elements on either
             # side to find q1.
             ###

             q1 = values[Math.floor(values.length / 4)]
             # Likewise for q3.
             q3 = values[Math.ceil(values.length * 3 / 4)]
             iqr = q3 - q1
             # Then find min and max values
             maxValue = q3 + iqr * 1.5
             minValue = q1 - (iqr * 1.5)
             # Then filter anything beyond or beneath these values.
             values.filter((x) -> x <= maxValue and x >= minValue)

         computeEstimate = ->
             if not arePending()
                 return

             totalElapsed = 0.0
             totalBuildTimes = 0.0
             nowTime = (Date.now() / 1000)

             totalPending = 0
             for builderId, startedTimes of pending
                 estimatedBuildTime = estimates[builderId]
                 if not estimatedBuildTime
                     return

                 for startedTime in startedTimes
                     totalPending += 1
                     elapsedTime = nowTime - startedTime
                     totalElapsed += elapsedTime
                     totalBuildTimes += estimates[builderId]

             #$log.debug('totalPending: ' + totalPending)
             #$log.debug('totalElapsedTime: ' + totalElapsed)
             #$log.debug('totalBuildTimes: ' + totalBuildTimes)

             $scope.pvalue = Math.min(100, Math.round((totalElapsed /
 totalBuildTimes) * 100))

             #$log.debug('pvalue: ' + $scope.pvalue)

         intervalPromise = null
         updateState = ->
             if intervalPromise != null
                 $interval.cancel(intervalPromise)
                 intervalPromise = null

             if arePending()
                 $scope.status = 'active'
                 intervalPromise = $interval (->
                     computeEstimate()
                     ), 1000, 0, true
             else if lastBuildResult != null
                 if lastBuildResult != RESULTS.SUCCESS
                     $scope.status = 'failure'
                 else
                     $scope.status = 'success'
             else
                 $scope.status = 'unknown'

         for builder in builders
             data.getBuilders(name: builder, limit:1).onNew = (builder) ->
                 builderBuildTimes = []
                 filteredBuilderBuildTimes = []
                 pending[builder.builderid] = []

                 xs = data.getBuilds(builderid: builder.builderId,
 complete: true, order: '-buildid', limit:500)
                 xs.onNew = (build) ->
                     builderBuildTimes.push(build.complete_at -
 build.started_at)
                     filteredBuilderBuildTimes =
 filterOutliers(builderBuildTimes)
                     if filteredBuilderBuildTimes.length > 0
                         averageBuildTime =
 (filteredBuilderBuildTimes.reduce (x, y) -> x + y) /
 filteredBuilderBuildTimes.length
                         estimates[builder.builderid] = averageBuildTime

                 ys = data.getBuilds(builderid: builder.builderid, order:
 '-buildid', complete: false)
                 ys.onNew = (build) ->
                     pending[builder.builderid].push(build.started_at)
                     updateState()
                 ys.onChange = (builds) ->
                     pending[builder.builderid] = []
                     for build in builds
                         $log.debug('build: ', build)
                         $log.debug('build.complete: ', build.complete)

                         if build.state_string == 'finished'
                             continue
                         pending[builder.builderid].push(build.started_at)
                     updateState()

                 zs = data.getBuilds(builderid: builder.builderId, order:
 '-buildid', limit:1)
                 zs.onNew = (build) ->
                     lastBuildResult = build.results
                     updateState()
                 zs.onChange = (builds) ->
                     for build in builds
                         lastBuildResult = build.results
                         updateState()
                         break

 }}}

--
Ticket URL: <http://trac.buildbot.net/ticket/3443>
Buildbot <http://buildbot.net/>
Buildbot: build/test automation


More information about the bugs mailing list