Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
gsexton committed Dec 7, 2024
1 parent 63f8c8a commit 46a64b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 5 additions & 5 deletions hdc302x/hdc302x.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ var writeHighAlertThresholds = devCommand{0x61, 0x1d}
var writeLowClearThresholds = devCommand{0x61, 0x0b}
var writeHighClearThresholds = devCommand{0x61, 0x16}

var invalidCRCError = errors.New("hdc302x: invalid crc")
var errInvalidCRC = errors.New("hdc302x: invalid crc")

const (
// Magic numbers for count to value conversions.
Expand Down Expand Up @@ -252,7 +252,7 @@ func (dev *Dev) Sense(env *physic.Env) error {
return fmt.Errorf("hdc302x: %w", err)
}

Check warning on line 253 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L252-L253

Added lines #L252 - L253 were not covered by tests
if crc8(res[:2]) != res[2] || crc8(res[3:5]) != res[5] {
return invalidCRCError
return errInvalidCRC
}

Check warning on line 256 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L255-L256

Added lines #L255 - L256 were not covered by tests
env.Temperature = countToTemperature(res)
env.Humidity = countToHumidity(res[3:])
Expand Down Expand Up @@ -359,7 +359,7 @@ func (dev *Dev) readAlertValues(cfg *Configuration) error {
return err
}

Check warning on line 360 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L359-L360

Added lines #L359 - L360 were not covered by tests
if crc8(r[:2]) != r[2] {
return invalidCRCError
return errInvalidCRC
}

Check warning on line 363 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L362-L363

Added lines #L362 - L363 were not covered by tests
wValue := uint16(r[0])<<8 | uint16(r[1])
// The alert value is returned as a 16 bit words, where bits 0-8 are the
Expand All @@ -382,7 +382,7 @@ func (dev *Dev) readOffsets(cfg *Configuration) error {
return fmt.Errorf("hdc302x: %w", err)
}

Check warning on line 383 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L382-L383

Added lines #L382 - L383 were not covered by tests
if crc8(r[:2]) != r[2] {
return invalidCRCError
return errInvalidCRC
}

Check warning on line 386 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L385-L386

Added lines #L385 - L386 were not covered by tests

// The result comes back as the humidity offset, followed by
Expand Down Expand Up @@ -425,7 +425,7 @@ func (dev *Dev) ReadStatus() (StatusWord, error) {
return 0, err
}

Check warning on line 426 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L425-L426

Added lines #L425 - L426 were not covered by tests
if crc8(r[:2]) != r[2] {
return 0, invalidCRCError
return 0, errInvalidCRC
}

Check warning on line 429 in hdc302x/hdc302x.go

View check run for this annotation

Codecov / codecov/patch

hdc302x/hdc302x.go#L428-L429

Added lines #L428 - L429 were not covered by tests
_ = dev.d.Tx(clearStatus, nil)
return StatusWord(r[0])<<8 | StatusWord(r[1]), nil
Expand Down
9 changes: 7 additions & 2 deletions hdc302x/hdc302x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math"
"os"
"sync"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -391,6 +392,8 @@ func TestSenseContinuous(t *testing.T) {

counter := atomic.Int32{}
tEnd := time.Now().UnixMilli() + int64(readCount+2)*1000
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
for {
time.Sleep(100 * time.Millisecond)
Expand All @@ -401,6 +404,7 @@ func TestSenseContinuous(t *testing.T) {
if err != nil {
t.Error(err)
}
wg.Done()
return
}
}
Expand All @@ -413,6 +417,7 @@ func TestSenseContinuous(t *testing.T) {
if counter.Load() != readCount {
t.Errorf("expected %d readings. received %d", readCount, counter.Load())
}
wg.Wait()
}

func TestConfiguration(t *testing.T) {
Expand Down Expand Up @@ -590,8 +595,8 @@ func TestHeater(t *testing.T) {
t.Logf("initial temperature: %s Humidity: %s", env.Temperature, env.Humidity)
err = dev.SetHeater(PowerFull)
defer func() {
if err := dev.SetHeater(PowerOff); err != nil {
t.Error(err)
if errOff := dev.SetHeater(PowerOff); errOff != nil {
t.Error(errOff)
}
}()
if err != nil {
Expand Down

0 comments on commit 46a64b9

Please sign in to comment.