fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package processor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/internal/eventbus"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEventBus_JobStatusChanged(t *testing.T) {
|
||||
bus := eventbus.NewLocalBus()
|
||||
ctx := context.Background()
|
||||
|
||||
var mu sync.Mutex
|
||||
var received []eventbus.Event
|
||||
|
||||
bus.Subscribe(eventbus.EventLoad, func(ctx context.Context, e eventbus.Event) error {
|
||||
mu.Lock()
|
||||
received = append(received, e)
|
||||
mu.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
evt := eventbus.Event{Type: eventbus.EventLoad, EntityType: "job", EntityID: "1", Payload: map[string]any{"jobId": 1}}
|
||||
err := bus.Publish(ctx, evt)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return len(received) >= 1
|
||||
}, 2*time.Second, 10*time.Millisecond)
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
assert.Equal(t, eventbus.EventLoad, received[0].Type)
|
||||
assert.Equal(t, "job", received[0].EntityType)
|
||||
assert.Equal(t, "1", received[0].EntityID)
|
||||
}
|
||||
|
||||
func TestEventBus_TempSlotChanged(t *testing.T) {
|
||||
bus := eventbus.NewLocalBus()
|
||||
ctx := context.Background()
|
||||
|
||||
var mu sync.Mutex
|
||||
var received []eventbus.Event
|
||||
|
||||
bus.Subscribe(eventbus.EventType("TEMP_SLOT_CHANGED"), func(ctx context.Context, e eventbus.Event) error {
|
||||
mu.Lock()
|
||||
received = append(received, e)
|
||||
mu.Unlock()
|
||||
return nil
|
||||
})
|
||||
|
||||
evt := eventbus.NewTempSlotChangedEvent(3, 100, "allocate")
|
||||
err := bus.Publish(ctx, evt)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Eventually(t, func() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return len(received) >= 1
|
||||
}, 2*time.Second, 10*time.Millisecond)
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
assert.Equal(t, "temp_slot", received[0].EntityType)
|
||||
assert.Equal(t, "3", received[0].EntityID)
|
||||
}
|
||||
Reference in New Issue
Block a user