50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
|
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/jobs"
|
|
)
|
|
|
|
func TestCreationCoordinatorDoesNotFailCreationWhenAtomicCommitOutcomeIsUnknown(t *testing.T) {
|
|
state := &commitUnknownCreationState{}
|
|
coordinator := &CreationCoordinator{charges: &chargeLedgerStub{}, state: state}
|
|
job := jobs.Job{
|
|
ID: "job-1",
|
|
Capability: "image.generate",
|
|
ReqKey: "wanx",
|
|
Billing: json.RawMessage(`{"status":"pending","amountFen":35}`),
|
|
UsageContext: json.RawMessage(`{"accountId":"account","organizationId":"org"}`),
|
|
}
|
|
|
|
_, _, err := coordinator.charge(context.Background(), job, false)
|
|
if err == nil || err.Error() != "charge generation job" {
|
|
t.Fatalf("err=%v, want generic infrastructure error", err)
|
|
}
|
|
if state.failCalls != 0 {
|
|
t.Fatalf("FailCreation calls=%d, want 0", state.failCalls)
|
|
}
|
|
}
|
|
|
|
type commitUnknownCreationState struct {
|
|
failCalls int
|
|
}
|
|
|
|
func (*commitUnknownCreationState) ChargeAndActivateCreation(context.Context, billing.ChargeRequest, json.RawMessage) (json.RawMessage, error) {
|
|
return nil, errors.Join(errors.New("commit response and reconciliation failed"), billing.ErrCommitOutcomeUnknown)
|
|
}
|
|
func (*commitUnknownCreationState) WriteBilling(context.Context, string, json.RawMessage) error {
|
|
return nil
|
|
}
|
|
func (*commitUnknownCreationState) ActivateCreation(context.Context, string, json.RawMessage) error {
|
|
return nil
|
|
}
|
|
func (s *commitUnknownCreationState) FailCreation(context.Context, jobs.Job) error {
|
|
s.failCalls++
|
|
return nil
|
|
}
|