Example #1
0
// RemoveChange, see ExpectationsStore interface.
func (s *SQLExpectationsStore) RemoveChange(changedDigests map[string][]string) (retErr error) {
	defer timer.New("removing exp change").Stop()

	const markRemovedStmt = `UPDATE exp_test_change
	                         SET removed = IF(removed IS NULL, ?, removed)
	                         WHERE (name=?) AND (digest=?)`

	// start a transaction
	tx, err := s.vdb.DB.Begin()
	if err != nil {
		return err
	}

	defer func() { retErr = database.CommitOrRollback(tx, retErr) }()

	// Mark all the digests as removed.
	now := util.TimeStampMs()
	for testName, digests := range changedDigests {
		for _, digest := range digests {
			if _, err = tx.Exec(markRemovedStmt, now, testName, digest); err != nil {
				return err
			}
		}
	}

	return nil
}
Example #2
0
// See  ExpectationsStore interface.
func (s *SQLExpectationsStore) UndoChange(changeID int, userID string) (map[string]types.TestClassification, error) {
	changeInfo, err := s.loadChangeEntry(changeID)
	if err != nil {
		return nil, err
	}

	// TODO(stephana): Enable undo and redo for undos.There is a small different
	// between a redo and an undo in that the undo restores the state before the
	// undo, while the redo replays the changes that were added in the original
	// change.

	// Refuse to undo a change that is the result of on undo.
	if changeInfo.UndoChangeID != 0 {
		return nil, fmt.Errorf("Unable to undo change %d which was created as an undo of change %d.", changeID, changeInfo.UndoChangeID)
	}

	// Get the expectations of tests of interest at that time.
	changes, err := s.getExpectationsAt(changeInfo)
	if err != nil {
		return nil, err
	}

	return changes, s.AddChangeWithTimeStamp(changes, userID, changeID, util.TimeStampMs())
}
Example #3
0
// See ExpectationsStore interface.
func (s *SQLExpectationsStore) AddChange(changedTests map[string]types.TestClassification, userId string) error {
	return s.AddChangeWithTimeStamp(changedTests, userId, 0, util.TimeStampMs())
}
Example #4
0
// PriorityTimeCombined combines a priority with a timestamp where the
// priority becomes the most significant digit and the time in Milliseconds
// the less significant digits. i.e. it allows to process elements of the
// same priority in order of their timestamps, but ahead of items with
// less priority.
func PriorityTimeCombined(priority int) int64 {
	ts := util.TimeStampMs()
	exp := int(math.Ceil(math.Log10(float64(ts)))) + 1
	return ts + int64(float64(priority)*math.Pow10(exp))
}